Example of calling axis2 WebService in Java

Source: Internet
Author: User
Tags addchild

Example of calling axis2 WebService in Java :,

Package CN. well. step. webService. kiosk; import Java. util. date; import Java. util. iterator; 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. axis2.addressing. endpointreference; import Org. apache. axis2.client. options; import Org. apache. axis2.axisfault; import Org. apache. axis2.constan TS; import Org. apache. axis2.client. serviceclient;/*** ** @ author mypc **/public class kioskclient {private final static string basepath = "http: // 192.168.0.150: 8080/server_huier/services/History "; public static Boolean isexist (string UID) throws exception {endpointreference targetepr = new endpointreference (basepath); omfactory FAC = omabstractfactory. getomfactory (); omnamespace omns = FAC. create Omnamespace ("http://webservice.kiosk.tsinghua.edu", "XS"); omelement method = FAC. createomelement ("Validate", omns); omelement value = FAC. createomelement ("uid", omns); value. addchild (FAC. createomtext (value, UID); method. addchild (value); options Options = new options (); options. setto (targetepr); options. settransportinprotocol (constants. transport_http); serviceclient sender = new serviceclient (); sender. se Toptions (options); omelement result = sender. sendreceive (method); string response = result. getfirstelement (). gettext (); If ("true "). equals (response) return true; return false ;} /*** get basic user information * @ Param persontogreet * @ return does not exist return NULL * @ throws exception */public static string getuserinfo (string UID) throws exception {endpointreference targetepr = new endpointreference (basepath); omfactory FAC = omabstra Ctfactory. getomfactory (); omnamespace omns = FAC. createomnamespace ("http://webservice.kiosk.tsinghua.edu", "XS"); omelement method = FAC. createomelement ("getuserinfo", omns); omelement value = FAC. createomelement ("uid", omns); value. addchild (FAC. createomtext (value, UID); method. addchild (value); options Options = new options (); options. setto (targetepr); options. settransportinprotocol (constants. transport_h TTP); serviceclient sender = new serviceclient (); sender. setoptions (options); omelement result = sender. sendreceive (method); string response = result. getfirstelement (). gettext (); If ("nouser ". equals (response) return NULL; string username, ethnic, sex, birthday, address; username = response. substring (response. indexof ("<username>") + 10, response. indexof ("</username>"); ethnic = response. substring (response. indexof (" <Ethnic> ") + 8, response. indexof ("</ethnic>"); Sex = response. substring (response. indexof ("<sex>") + 5, response. indexof ("</sex>"); Birthday = response. substring (response. indexof ("<birthday>") + 10, response. indexof ("</birthday>"); Address = response. substring (response. indexof ("<address>") + 9, response. indexof ("</address>"); Return username + "," + ethnic + "," + sex + "," + birthday + "," + address ;} // http: // 192.168.0.45: 8080 /Server_huier/services/history/gettyperesult? Uid = 330501198812062255 & type = weight & datestart = 2011-11-12/*** get basic user information * @ Param persontogreet * @ Param DT date format: 2011-11-12 11:05:33 * @ return does not exist return NULL * @ throws exception */public static string getweight (string uid, string DT) throws exception {endpointreference targetepr = new endpointreference (basepath ); omfactory FAC = omw.actfactory. getomfactory (); omnamespace omns = FAC. createomnamespace ("http://webservice.kiosk.tsinghua.edu", "XS"); omelement method = FAC. createomelement ("gettyperesult", omns); omelement uide = FAC. createomelement ("uid", omns); uide. addchild (FAC. createomtext (uide, UID); omelement Typee = FAC. createomelement ("type", omns); Typee. addchild (FAC. createomtext (Typee, "weight"); omelement datestarte = FAC. createomelement ("datestart", omns); datestarte. addchild (FAC. createomtext (datestarte, DT); method. addchild (uide); method. addchild (Typee); method. addchild (datestarte); options Options = new options (); options. setto (targetepr); options. settransportinprotocol (constants. transport_http); serviceclient sender = new serviceclient (); sender. setoptions (options); omelement result = sender. sendreceive (method); string response = result. getfirstelement (). gettext (); If ("nouser ". equals (response) return NULL; string username, ethnic, sex, birthday, address; return response;} public static void main (string [] ARGs) {try {// system. out. println (kioskclient. isexist ("330501198812062255"); // system. out. println (kioskclient. getuserinfo ("330501198812062255"); system. out. println (kioskclient. getweight ("330501198812062255", "11:05:33");} catch (exception e) {e. printstacktrace (); system. out. println (E. tostring ());}}}

The call result is as follows:

<data><type value='weight'><WEIGHT begin_time='2013-06-22 18:09:34'><weight value='86.2' />

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.