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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM