我正在使用 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; charset=utf-8' 不是预期的类型 'multipart/related; 类型="应用程序/xop+xml"'。线程“主”com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl 中的异常:com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:错误响应:(415Cannot process the message because the content type '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:错误响应:
原因:
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 接收这种内容类型?我也尝试过使用轴。我收到了同样的错误信息。