• Java Axis2 webservice


    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);
    
    	}
    
    	/**
    	 * 方法二: 应用document方式调用 用ducument方式应用现对繁琐而灵活。现在用的比较多。因为真正摆脱了我们不想要的耦合
    	 */
    	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>暂无</DAMAGEGRADENAME><EVENTDESC>北四环西路辅路与六郞庄路交叉口向北50米六郞庄路东侧有绿地脏乱</EVENTDESC><EVENTTYPECODE>1</EVENTTYPECODE><PARTCODE></PARTCODE><ADDRESS>六郎庄37号杆(东南20米)</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海淀管字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>冯文越</SIGNHUMANNAME><SIGNDATE>2016-11-11T08:51:13</SIGNDATE></CASEOPERATIONDETAIL></ROOTMAIN>";
    
    			Options options = new Options();
    			// 指定调用WebService的URL
    			EndpointReference targetEPR = new EndpointReference(url);
    			options.setTo(targetEPR);
    			// options.setAction("urn:getPrice");
    
    			ServiceClient sender = new ServiceClient();
    			sender.setOptions(options);
    
    			OMFactory fac = OMAbstractFactory.getOMFactory();
    			// 命名空间,有时命名空间不增加没事,不过最好加上,因为有时有事,你懂的
    			OMNamespace omNs = fac.createOMNamespace(namespace, methodName);
    
    			/* 以下设置添加SOAP消息头 */
    			OMElement SenderCode = fac.createOMElement("SenderCode", omNs);
    			OMElement ReceiverCode = fac.createOMElement("ReceiverCode", omNs);
    			OMElement OperationCode = fac
    					.createOMElement("OperationCode", omNs);
    			OMElement MessageID = fac.createOMElement("MessageID", omNs);
    			SenderCode.setText("002");
    			ReceiverCode.setText("000");
    			OperationCode.setText("011");
    			MessageID.setText("10000000000000000");
    
    			sender.addHeader(SenderCode);
    			sender.addHeader(ReceiverCode);
    			sender.addHeader(OperationCode);
    			sender.addHeader(MessageID);
    
    			/* 以下设置要发送的参数 */
    			// 指定方法 名
    			OMElement method = fac.createOMElement(methodName, omNs);
    			// 指定方法的参数名
    			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();
    		}
    	}
    
    }
    

      

  • 相关阅读:
    求概率 Bag of mice CodeForces
    HDU 3853 LOOPS(概率DP)
    HDU 4405 Aeroplane chess (概率DP & 期望)
    求期望 ZOJ 3329 One Person Game
    poj 3774 Scout YYF I (矩阵优化的概率DP)
    codeforces 600D Area of Two Circles' Intersection
    codeforces 600A Extract Numbers
    codeforces 600C Make Palindrome
    POJ
    POJ
  • 原文地址:https://www.cnblogs.com/chenghu/p/8571553.html
Copyright © 2020-2023  润新知