我正在尝试调用一些WS。我的本地计算机上有服务器和客户端。我对消息内容100%肯定,它来自服务器到客户端,没有任何变化。问题是客户端创建了不正确的SOAPMessage
对象,其中soapPart下的信封字段等于null。
客户端代码:
SOAPMessage responseMsg = conn.call(msg, urlEndpoint);
服务器端代码:
SOAPEnvelope envelope = sp.getEnvelope();
SOAPHeader hdr = envelope.getHeader();
SOAPBody bdy = envelope.getBody();
bdy.addBodyElement(envelope.createName("response", "soa", "http://www.sbg.com"));
return msg;
Id调试窗口我看到以下内容:
1)服务器端调试窗口
2)客户端调试窗口
我正在使用SAAJ进行通信和JDK 1.6。
有人可以协助解决这个问题吗?
答案 0 :(得分:1)
答案 1 :(得分:0)
试试这个:
SOAPMessage sm = MessageFactory.newInstance().createMessage();
sm.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
sm.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
SOAPPart sp = sm.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
se.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
se.setAttribute("xmlns:SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/");
se.setAttribute("xmlns:soa", "http://www.sbg.com");
SOAPBody sb = sm.getSOAPBody();
SOAPBodyElement el = sb.addBodyElement(new QName("http://www.sbg.com", "response", "soa"));
el.setAttribute("_ctxID", "cid=xref_members,cn=admin");
el.setAttribute("status", "OK");
SOAPElement in = el.addChildElement("response_code");
in.setValue("0000");
sm.writeTo(System.out);