Use axis to call the. NET Server

Source: Internet
Author: User

After jdk5.0, It is very convenient to establish web services. Whether xfire is powerful, or netbeans is quick, I am deeply impressed. However, it is not so convenient in jdk1.4. This is especially true when a server is generated using a language other than Java.

The following is the code for using axis to access the. NET Server under jdk1.4, which is also collected online. The link cannot be found.

Import javax. xml. namespace. QNAME;
Import javax. xml. rpc. parametermode;

Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Import org. Apache. axis. encoding. xmltype;

Public class axisdemo ...{

Public static void main (string [] ARGs )...{

Try ...{
String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx ";
Service = new service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (New java.net. URL (endpoint ));
QNAME Qn = new QNAME ("http://WebXml.com.cn/", "qqcode ");
Call. addparameter (qN, xmltype. xsd_string, parametermode. In );
Call. setreturntype (xmltype. xsd_string );
Call. setusesoapaction (true );
Call. setsoapactionuri ("http://WebXml.com.cn/qqCheckOnline ");
Call. setoperationname (New QNAME ("http://WebXml.com.cn/", "qqcheckonline "));
String qqcd = "32083343 ";
String ret = (string) Call. Invoke (new object []... {qqcd });
System. Out. println ("got Result:" + RET );
} Catch (exception e )...{
System. Err. println (E. tostring ());
}
}
}

Where:

If the parameter is defined as follows, it is very likely that it cannot be passed to. net. (If Java is used on the server, it seems that there is no problem)

Call. addparameter ("Qqcode", Xmltype. xsd_string, parametermode. In );

Note:

New QNAME ("http://www.w3.org/2001/XMLSchema", "float") is equivalent to org. Apache. axis. encoding. xmltype. xsd_float.

Operationstyle is divided into wrapped, document, RPC, message, and other methods. When you call the. NET Server, you generally need to set it.

For more information, see:

Http://www.ibm.com/developerworks/cn/webservices/ws-soa-intersoap/

Http://www.ibm.com/developerworks/cn/webservices/ws-docstyle/

Http://dev2dev.bea.com.cn/blog/shallon/200711/30_714.html

As follows:

Import javax. xml. namespace. QNAME;
Import javax. xml. rpc. parametermode;

Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;

Public class testclient ...{

Public static void main (string [] ARGs )...{
Try ...{
String endpoint = "http://chs.gotdotnet.com/quickstart/aspplus/samples/services/MathService/VB/MathService.asmx ";
Service = new service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (New java.net. URL (endpoint ));
Float I = new float (1 );
Float J = new float (2 );
QNAME p0 = new QNAME ("http://tempuri.org/", "");
Call. addparameter (P0, new QNAME ("http://www.w3.org/2001/XMLSchema", "float"), parametermode. In );
QNAME p1 = new QNAME ("http://tempuri.org/", "B ");
Call. addparameter (P1, org. Apache. axis. encoding. xmltype. xsd_float, parametermode. In );
Call. setreturntype (New QNAME ("http://www.w3.org/2001/XMLSchema", "float "));
Call. setusesoapaction (true );
Call. setsoapactionuri ("http://tempuri.org/Add ");
Call. setencodingstyle (null );
Call. setproperty (Org. Apache. axis. axisengine. prop_domultirefs, Boolean. False );
Call. setproperty (Org. Apache. axis. Client. Call. send_type_attr, Boolean. False );
Call. setoperationstyle ("wrapped ");
Call. setoperationname (New QNAME ("http://tempuri.org/", "add "));
Float ret = (float) Call. Invoke (new object []... {I, j });
System. Out. println ("got Result:" + RET );
} Catch (exception e )...{
System. Err. println (E. tostring ());
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.