我可以使用 Web 服务客户端类来获取结果,但我想要在我的 JavaSE 程序中完整的 SOAP 消息而不是文本结果。我怎样才能做到这一点?任何的想法?
问问题
2355 次
2 回答
2
就在这里。
用于Dispatch<Source>
处理 SOAP 消息JAX-WS Dispatch。
示例
免责声明:甚至没有尝试编译代码:
//xmlString has the xml message to send to the web service
StreamSource xmlMsg = new StreamSource(new StringReader(xmlString));
//Create URL of web service. Place your URL for WSDL
URL wsdlURL = new URL("http://10.5.2.10:8080/path/service?wsdl");
QName serviceName = new QName("http://example.com", "TrivialWebService");
Service s = Service.create(wsdlURL, serviceName);
QName portName = new QName("http://example.com", "TrivialWebServicePort");
//Service.Mode.MESSAGE works on SOAP msg (as opposed to Service.Mode.PAYLOAD)
Dispatch<Source> dispatch = createDispatch(portName,
Source.class,
Service.Mode.MESSAGE);
//Send request
Source reply = dispatch.invoke(xmlMsg);
DOMResult domResponse = new DOMResult();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.transform(reply, domResponse);
//Now use DOM APIs
您还可以指定是否要处理 HTTP 有效负载(作为 XML)(即 SOAP 信封)或 SOAP 有效负载(即响应)。
您将编写代码来处理原始 XML(例如使用 DOM)。
如果您使用 JAX-WS 或 CXF,则可以使用此 api。
对于 AXIS2,它也可以在 XML 上工作。只是一些特定的 apis
当然,您也可以使用 SAAJ。
于 2011-07-03T07:40:04.157 回答
0
整个 SOAP 消息将包含在 HTTP 请求对象 (HttpServletRequest) 中。这将为您提供标题、正文和其他所有内容。
于 2011-07-03T02:38:01.230 回答