Java WebService (asmx) Call examples

Source: Internet
Author: User

I wrote several call examples:

1,

Import org. Apache. axis. Client .*;
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Import javax. xml. namespace. QNAME;
Import javax. xml. rpc. parametermode;
Import javax. xml. rpc. jaxrpcexception;
Import javax. xml. rpc. servicefactory;

Public class testwebservice {

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
System. Out. println ("start invoking ....");
Try
{
String endpoint = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx ";
Service = new service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (New java.net. URL (endpoint ));
Call. setoperation ("getversiontime ");
Call. setusesoapaction (true );
Call. setsoapactionuri ("http://WebXml.com.cn/getVersionTime ");

Call. setoperationname (New QNAME (""));
Call. setreturntype (Org. Apache. axis. encoding. xmltype. xsd_string );
String STR = (string) Call. Invoke (new object [] {});
System. Out. println (STR );
} Catch (exception E)
{
E. printstacktrace ();
}
}

}

2,

Import java. util. Collections list;
Import java. util. List;
Import java. util. Map;
Import java. util. vector;

Import javax. xml. namespace. QNAME;

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

Public class getipcontent
{
Private string url = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx ";
Private string soapaction = "http://WebXml.com.cn /";


Public getipcontent ()
{
Service = new service ();
Try {
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (URL );
Call. setoperationname (New QNAME (soapaction, "getgeoipcontext "));

Call. setreturntype (New QNAME (soapaction, "getgeoipcontext"), vector. Class );


Call. setusesoapaction (true );
Call. setsoapactionuri (soapaction + "getgeoipcontext ");

Vector v = (vector) Call. Invoke (new object [] {}); // call a method and PASS Parameters
For (INT I = 0; I <v. Size (); I ++)
{
System. Out. println (V. Get (I ));
}

} Catch (exception ex)
{
Ex. printstacktrace ();
}
}

Public static void main (string ARGs [])
{
Getipcontent GIP = new getipcontent ();
}


}

3,

Import java. util. Collections list;
Import java. util. List;
Import java. util. Map;
Import java. util. vector;

Import javax. xml. namespace. QNAME;

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

Public class putweather
{
Private string url = "Address of the provided Interface
Private string soapaction = "http://WebXml.com.cn/"; // domain name, which is defined on the server

Public putweather ()
{
String city = "Beijing ";
Service = new service ();
Try {
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (URL );
Call. setoperationname (New QNAME (soapaction, "getweatherbycityname"); // you can specify the method to call.
Call. addparameter (New QNAME (soapaction, "thecityname"), // set the parameter to be passed
Org. Apache. axis. encoding. xmltype. xsd_string,
Javax. xml. rpc. parametermode. In );
Call. setreturntype (New QNAME (soapaction, "getweatherbycityname"), vector. Class); // data type to be returned (custom type)

// Call. setreturntype (Org. Apache. axis. encoding. xmltype. xsd_string); // (standard type)

Call. setusesoapaction (true );
Call. setsoapactionuri (soapaction + "getweatherbycityname ");

Vector v = (vector) Call. Invoke (new object [] {city}); // call the method and PASS Parameters
For (INT I = 0; I <v. Size (); I ++)
{
System. Out. println (V. Get (I ));
}

} Catch (exception ex)
{
Ex. printstacktrace ();
}
}

Public static void main (string ARGs [])
{
Putweather PW = new putweather ();
}


}

The third one is reprinted. Unfortunately, I don't know the address ......

--! Sorry

Related Article

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.