调用wsdl接口,参数是xml格式

匿名 (未验证) 提交于 2019-12-02 23:32:01

1、最近太累了,好困。闲话少许直奔主题吧。上代码

try{             String wsurl = "http://172.16.16.236:9999/xxx/ws/WSService?wsdl";           String Str = "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wss="http://wsservice.userInfo.uias.jit.com/">     <soapenv:Header />     <soapenv:Body>         <wss:synchronizeDatas>             <appMark>TEST</appMark>             <utsNodeInfo><![CDATA[<?xml version="1.0" encoding="UTF-8"?><datas><data><id>#id#</id></data></datas>]]></utsNodeInfo></wss:synchronizeDatas></soapenv:Body></soapenv:Envelope>";             byte[] content;             content = Str.getBytes("UTF-8");             HttpClient httpClient = new HttpClient();             httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);             PostMethod method = new PostMethod(url);             httpClient.getParams().setContentCharset("UTF-8");             method.setRequestHeader("Connection", "close");             RequestEntity requestEntity = new ByteArrayRequestEntity(content,                     "application/xml; charset=UTF-8");             method.setRequestEntity(requestEntity);                          int statusCode = httpClient.executeMethod(method);             if(statusCode==200){                 String xmlStr =method.getResponseBodyAsString();                 Document document = DocumentHelper.parseText(xmlStr);                 Element root = document.getRootElement();                 Element body = root.element("Body");                 Element response = (Element) body.elements().get(0);                 Element pst = (Element) response.elements().get(0);                 Element retCode = pst.element("code");                 String a = retCode.getText();                 code = a.charAt(0);                 Element id = pst.element("id");                 i = id.getText();                 Element message = pst.element("message");                 m = message.getText();             }          }catch(Exception e){             e.printStackTrace();             log.error(e.getMessage(), e);         }

2、其实整体也没什么特别,但是有一个地方要注意就是<![CDATA[]]>的引用。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!