Example of Java calling WebService (asmx) __java

Source: Internet
Author: User
Import java.util.LinkedList;
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= "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";//provide an address for an interface   Private String soapaction= "http://WebXml.com.cn/";        
         Domain name, which is the public putweather () {String city= "Beijing" defined in the server;
         Service service=new service ();            
             try{call call= (call) Service.createcall ();            
             Call.settargetendpointaddress (URL); Call.setoperationname (New QName (SOAPAction, "getweatherbycityname")); Set which method to invoke Call.addparameter (new QName (SOAPAction, "Thecityname"),//Set parameters to pass Org.apache
             . Axis.encoding.XMLType.XSD_STRING, Javax.xml.rpc.ParameterMode.IN); Call.setreturntype (New QName (Soapaction, "getweatherbycityname"), Vector.class);
            
             The data type to return (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 method and pass parameter 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 ();		 }
}

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.