我正在使用SAAJ Soap连接来调用第三方Web服务。似乎已经使用WCF或C#创建了Web服务。当我使用SOAP UI工具调用我的URL时,它正常工作并成功接收响应。当我试图通过以下java代码访问我收到错误。
代码:
public class SOAPClientSAAJNew {
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "XXX";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
}
错误:
严重:SAAJ0008:反应不佳;无法处理邮件,因为内容类型为' text / xml;字符集= UTF-8'不是预期的类型&multi39 / multi;类型="应用程序/ XOP + XML"&#39 ;. 线程" main"中的例外情况com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:响应错误:(415无法处理邮件,因为内容类型' text / xml; charset = utf-8'不是预期的类型&multipart / related; type =" application / xop + xml"'。 在com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148) 在example.SOAPClientSAAJNew.main(SOAPClientSAAJNew.java:25) 引起:com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:错误的响应:(415无法处理消息,因为内容类型' text / xml; charset = utf-8'不是预期的类型' multipart / related; type =" application / xop + xml"'。 在com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:258) 在com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144) ......还有1个
原因:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (415Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'multipart/related; type="application/xop+xml"'.
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:258)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)
at example.SOAPClientSAAJNew.main(SOAPClientSAAJNew.java:25)
在标题部分的SOAP UI工具中,我可以看到我收到的Content-Type
HTTP/1.1 200 OK
Content-Length: 35512
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:02b574c6-30b8-45f3-a9fc-5d5deac849ab+id=14";start-info="application/soap+xml"
Server: Microsoft-IIS/7.0
MIME-Version: 1.0
Date: Wed, 10 Sep 2014 12:55:29 GMT
如何使用java接收此内容类型?我也试过使用轴。我收到的错误信息相同。