设为首页 加入收藏

TOP

调用wsdl接口,参数是xml格式
2019-09-02 23:19:04 】 浏览:8
Tags:调用 wsdl 接口 参数 xml 格式

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Spring方法级别数据校验:@Valida.. 下一篇SSM Note

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目