最近在与其他系统联调,涉及到数据传输,沟通后,统一用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");