Axis calls WebService to view mobile phone information (fixed number)

Source: Internet
Author: User
1. Download axis

2. Create a web project under myeclipse

Import the Lib package under axis to the Lib center of the project.

3. Create a JavaBean telephoneaxis. Java

CodeAs 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 telephoneaxis {Private Static endpointreference targetepr = new endpointreference ("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"); Public void getresult () throws exception {string S = NULL; serviceclient sender = new serviceclient (); sender. setoptions (buildoptions (); omelement result = sender. sendreceive (buildparam (); s = result. getfirstelement (). gettext (); system. out. println (s);} Private Static omelement buildparam () {omfactory FAC = omabstractfactory. getomfactory (); omnamespace omns = FAC. createomnamespace ("http://WebXml.com.cn/", ""); omelement DATA = FAC. createomelement ("getmobilecodeinfo", omns); omelement inner = FAC. createomelement ("mobilecode", omns); inner. settext ("15874333 ***"); data. addchild (inner); return data;} Private Static options buildoptions () {options Options = new options (); options. setsoapversionuri (soap11constants. soap_envelope_namespace_uri); options. setaction ("http://WebXml.com.cn/getMobileCodeInfo"); 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 {telephoneaxis S = new telephoneaxis (); S. getresult ();}}

4. Success. If you need to enter the phone number dynamically, you can add an index. jsp page.

5. To be continued .....

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.