实际开发笔记:WebService接口调用二

最近在与其他系统联调,涉及到数据传输,沟通后,统一用WebService接口,第二种方式:

WebService接口报文:


<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
   <soapenv:Header/>
   <soapenv:Body>
      <paos:Query soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <id xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</id >
         <userid xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</userid>
         <password xsi:type="xsd:int">?</password>
      </paos:Query>
   </soapenv:Body>
</soapenv:Envelope>

调用此接口:返回的是XML文件,需要解析报文

            
        Service service = new Service();// 创建一个服务(service)调用(call) 
        Call call;
	String callRet = new String();//返回串
        try {
		call = (Call)service.createCall();// 通过service创建call对象  
		call.setTargetEndpointAddress(new java.net.URL(requestUri));//设置service所在URL 
	        call.setOperationName("Query");  //设置调用方法名 
	        callRet = (String)call.invoke(new Object[]{id,userid ,password}); 
	        
	} catch (ServiceException e) {
			e.printStackTrace(); 
	}  
        
        Document dom=DocumentHelper.parseText(callRet);
        Element root=dom.getRootElement();
	String resultCode=root.element("result_code").getText();
	String resultMsg=root.element("result_msg").getText();
	String serialCode=root.element("serial_code").getText();
	Element resultContent=root.element("result_content");
		
		

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值