Axis calls WebService to view weather conditions (fixed area)

Source: Internet
Author: User

1. The procedure is the same as checking the mobile phone number of your blog.

2. Create a weatheraxis. Java File

The Code is as follows:

Package COM. tools; import Org. apache. axiom. om. omabstractfactory; import Org. apache. axiom. om. omelement; import Org. apache. axiom. om. omfactory; import Org. apache. axiom. om. omnamespace; import Org. apache. axiom. soap. soap11constants; import Org. apache. axis2.constants; import Org. apache. axis2.addressing. endpointreference; import Org. apache. axis2.client. options; import Org. apache. axis2.client. serviceclient; import Org. apache. axis2.transport. HTTP. httpconstants; import Org. apache. axis2.transport. HTTP. httptransportproperties. proxyproperties; import Org. apache. commons. logging. log; import Org. apache. commons. logging. logfactory; public class weatheraxis {Private Static endpointreference targetepr = new endpointreference ("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"); // Private Static endpointreference targetepr = new endpointreference (// "http: // 210.43.64.106/service. asmx "); Public void getresult () throws exception {serviceclient sender = new serviceclient (); sender. setoptions (buildoptions (); omelement result = sender. sendreceive (buildparam (); system. out. println (result);} Private Static omelement buildparam () {omfactory FAC = omabstractfactory. getomfactory (); omnamespace omns = FAC. createomnamespace ("http://WebXml.com.cn/", ""); // omnamespace omns = FAC. createomnamespace ("http://tempuri.org/", ""); omelement DATA = FAC. createomelement ("getweatherbycityname", omns); // omelement DATA = FAC. createomelement ("xscheckpassword", omns); omelement inner = FAC. createomelement ("thecityname", omns); // omelement inner = FAC. createomelement ("XH", omns); inner. settext ("Jishou"); // omelement inner2 = FAC. createomelement ("XM", omns); // inner. settext ("2008198821"); data. addchild (inner); // data. addchild (inner2); return data;} Private Static options buildoptions () {options Options = new options (); options. setsoapversionuri (soap11constants. soap_envelope_namespace_uri); options. setaction ("http://WebXml.com.cn/getWeatherbyCityName"); // options. setaction ("http: // 210.43.64.106/xscheckpassword"); options. setto (targetepr); // options. if setproperty does not access the Internet through a proxy, this sentence can save // options. setproperty (httpconstants. proxy, buildproxy (); options. settransportinprotocol (constants. transport_http); return options;}/*** when the local machine uses a proxy server to access the Internet, you need to set the proxy * @ return */public static proxyproperties buildproxy () {proxyproperties = new proxyproperties (); proxyproperties. setproxyname ("proxy name"); proxyproperties. setproxyport (8080); Return proxyproperties;} public static void main (string [] ARGs) throws exception {weatheraxis S = new weatheraxis (); S. getresult ();}}

 

3. Success.

 

 

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.