欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-07-05 10:56:33
1、最近太累了,好困。闲话少许直奔主题吧。上代码 2、其实整体也没什么特别,但是有一个地方要注意就是的引用。 ......

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