使用 SoapUI,我构建了以下 XML 信封并将其封装在一个字符串中。
ProcessJournal 是一个没有参数的方法,它返回一个字符串。
String soapText = "<Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:upd=\"http://webservices.vm.vmc/UpdateCMA/\">" +
"<Header/>" +
"<Body>" +
"<upd:ProcessJournal/>" +
"</Body>" +
"</Envelope>";
现在...我只想调用上面定义的 Web 服务。并找到了一些示例代码
// Create SoapMessage
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
// Load the SOAP text into a stream source
byte[] buffer = soapText.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
StreamSource source = new StreamSource(stream);
// Set contents of message
soapPart.setContent(source);
// -- DONE
message.writeTo(System.out);
//Try accessing the SOAPBody
SOAPBody soapBody = message.getSOAPBody();
问题是,在 message.getSOAPBody();,我得到一个错误
XML-22103: (Fatal Error) DOMResult can not be this kind of node.
Apr 16, 2013 12:05:06 PM com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope
SEVERE: SAAJ0511: Unable to create envelope from given source
我找到的所有各种示例在执行 getSOAPBody() 时最终都会出现相同类型的错误。