使用SoapUI我已經構建了以下XML信封並將其封裝在字符串中。Java - 從字符串XML信封使用SOAP Web服務
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()時出現相同類型的錯誤。
謝謝你的帖子。我們最終走了一條不同的路線,因爲沒有人能夠實現它的工作。但是,當需要再次嘗試時,我會嘗試你的建議:)謝謝! – adam