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

2019-05-08 07:28:18来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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[]]>的引用。


原文链接:https://www.cnblogs.com/city-light/p/10816118.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:【原】无脑操作:Eclipse + Maven + jFinal + MariaDB 环境搭建

下一篇:SpringBoot 2.x (4):配置文件与单元测试