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.axisfault;import Org.apache.axis2.addressing.endpointreference;import Org.apache.axis2.client.options;import Org.apache.axis2.client.serviceclient;public class TestAxis2 {public static void main (string[] args) {String url = "http: 192.168.1.1/XXX/DTISERVICE?WSDL "; String namespace = "http://xxx.com.cn"; String methodName = "ProcessMessage"; testdocument (url, namespace, methodName);} /** * Method Two: The application of the document mode call with the Ducument method is cumbersome and flexible. It's more used now. Because really get rid of the coupling we don't want */public static void testdocument (string url, string namespace,string methodName) {try {string xmlData = " <rootmain><casemain><subtypecode>10101</subtypecode><eventgradecode>1</ Eventgradecode><eventid>2875715</eventid><damagegradename> No </DAMAGEGRADENAME>< Eventdesc> North four Ring West Road Auxiliary Road and six Lang Zhuang Road intersection North 50.6-meter Lang Zhuang Road East there is green mess ≪/eventdesc><eventtypecode>1</eventtypecode><partcode></partcode><address> Liulangzhuang No. 37th Pole (20 m southeast) </address><operatorname></operatorname><tasknum>16110803978</tasknum ><CELLCODE>11010802300219</CELLCODE><TELNUM>13910351520</TELNUM><INSTDATE> 2016-11-08t14:24:12</instdate><streetcode>110108023</streetcode><createdate> 2016-11-08t14:24:12</createdate><recdispnum>2016 Haidian Tube Word 1793973</recdispnum><maintypecode> 1</maintypecode><eventsrccode>1</eventsrccode><communitycode>110108023002</ Communitycode><districtcode>110108</districtcode><patrolname> 杜文森 </PATROLNAME>< Coordinatey>312853.0</coordinatey><coordinatex>494444.0</coordinatex></casemain> <CASEOPERATIONDETAIL><SIGNHUMANNAME> Thickets Yue </signhumanname><signdate>2016-11-11t08:51:13 </signdate></caseoperationdetaiL></rootmain> "; Options options = new options ();//Specify Urlendpointreference TARGETEPR to call WebService = new EndpointReference (URL); Options.setto (TARGETEPR);//Options.setaction ("Urn:getprice"); ServiceClient sender = new ServiceClient (); sender.setoptions (options); omfactory FAC = Omabstractfactory.getomfactory ( );//namespace, sometimes the namespace does not increase nothing, but better add, because sometimes something, you know omnamespace Omns = Fac.createomnamespace (namespace, methodName);/* The following settings add the SOAP message header */omelement SenderCode = fac.createomelement ("SenderCode", omns); Omelement Receivercode = Fac.createomelement ("Receivercode", omns); Omelement Operationcode = Fac.createomelement ("OperationCode", omNs); O Melement MessageID = fac.createomelement ("MessageID", omns); Sendercode.settext ("002"); Receivercode.settext ("the"); Operationcode.settext ("011"); Messageid.settext ("10000000000000000"); Sender.addheader (SenderCode); Sender.addheader (ReceiverCode); Sender.addheader (Operationcode); Sender.addheader (MessageID);/* The following sets the parameters to be sent *///the specified method name Omelement methods = Fac.createomelement(MethodName, omns);//The parameter name of the specified method omelement symbol = fac.createomelement ("Messageinfo", Omns); Symbol.settext (xmlData);// Symbol.addchild (Fac.createomtext (symbol, xmlData)); Method.addchild (symbol); Method.build (); Omelement res = Sender.sendreceive (method); String result = Res.getfirstelement (). GetText (); SYSTEM.OUT.PRINTLN (result);} catch (Axisfault Axisfault) {axisfault.printstacktrace ();}}}
Java Axis2 WebService