WCF 无法分析 Java soap 响应
本文关键字:Java soap 响应 WCF | 更新日期: 2023-09-27 18:31:57
我有来自Java Web服务的响应:
HTTP/1.1 200 OK
Date: Mon, 23 Apr 2012 12:08:50 GMT
Server: Jetty/5.1.14 (Linux/2.6.18-274.17.1.el5xen x86 java/1.6.0
Content-Type: text/xml; charset=utf-8
Content-Length: 571
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335182931028
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:14B7343BF98675BB5D1335182931029@apache.org>
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:loginResponse xmlns:ns1="http://www.telelogic.com/change/types"><token>206398089429929753</token></ns1:loginResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335182931028--
WCF的例外告诉我The data at the root level is invalid. Line 1, position 1.
我的应用程序配置如下:
<customBinding>
<binding>
<!--<messageModifier />-->
<!--<mtomMessageEncoding messageVersion="Soap11" writeEncoding="utf-8" />-->
<textMessageEncoding writeEncoding="utf-8" messageVersion="Soap11" />
<httpsTransport
requireClientCertificate="false"
transferMode="Buffered" />
</binding>
</customBinding>
如您所见,我已经尝试了不同的设置,例如 mtom/text encodig、消息版本的 soap11/soap12、用于传输模式的缓冲和响应流。我有点卡住了。当我用小提琴手剥离一些响应时,我让它工作了:
HTTP/1.1 200 OK
Date: Mon, 23 Apr 2012 14:21:44 GMT
Server: Jetty/5.1.14 (Linux/2.6.18-274.17.1.el5xen x86 java/1.6.0
Content-Type: text/xml; charset=utf-8
Content-Length: 571
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:loginResponse xmlns:ns1="http://www.telelogic.com/change/types"><token>206398089429929753</token></ns1:loginResponse></soapenv:Body></soapenv:Envelope>
我错过了什么吗?我需要配置设置的神奇组合吗?
我还尝试了机器人 IClientMessageFormatter 和 IClientMessageInspector,但它们在堆栈中似乎都太高了,因为 WCF 已经失败了,ProtocolException 告诉The data at the root level is invalid. Line 1, position 1.
。
我从 WCF 示例中挂钩了 ChannelMessageInterceptor。我以为我得到了它的工作,但现在我收到了来自 java 服务的异常:
HTTP/1.1 500 Internal Server Error
Date: Mon, 23 Apr 2012 14:40:05 GMT
Server: Jetty/5.1.14 (Linux/2.6.18-274.17.1.el5xen x86 java/1.6.0
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335192006387; type="application/xop+xml"; start="<0.urn:uuid:14B7343BF98675BB5D1335192006388@apache.org>"; start-info="application/soap+xml"; action="http://www.telelogic.com/change/ChangeService/login/Fault/LoginFault";charset=UTF-8
Content-Length: 2853
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335192006387
Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:14B7343BF98675BB5D1335192006388@apache.org>
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><soapenv:Fault xmlns:axis2ns15="http://www.w3.org/2003/05/soap-envelope"><soapenv:Code><soapenv:Value>axis2ns15:MustUnderstand</soapenv:Value></soapenv:Code><soapenv:Reason><soapenv:Text xml:lang="en-US">Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action</soapenv:Text></soapenv:Reason><soapenv:Detail><Exception>org.apache.axis2.AxisFault: Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action
at org.apache.axis2.engine.AxisEngine.checkMustUnderstand(AxisEngine.java:88)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:137)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:121)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
at compressionFilters.CompressionFilter.doFilter(CompressionFilter.java:192)
at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
at com.telelogic.cs.filters.StrutsCharsetFilter.doFilter(StrutsCharsetFilter.java:44)
at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.http.HttpServer.service(HttpServer.java:909)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
</Exception></soapenv:Detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335192006387--
至少它告诉我他们正在使用安讯士?我还看到异常消息告诉我响应的内容类型与绑定中的类型不匹配,但目前无法重现它们。
看起来很像这个问题。我还尝试了带有附件编码器的WCF Soap,但它也一直在唠叨Data at the root level is invalid. Line 1, position 1.
(但现在直接在XmlException而不是ProtocolException中)。
更新我有WCF SWA工作!
包含附件的示例邮件:
HTTP/1.1 200 OK
Date: Tue, 24 Apr 2012 11:27:40 GMT
Server: Jetty/5.1.14 (Linux/2.6.18-274.17.1.el5xen x86 java/1.6.0
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335266861287; type="application/xop+xml"; start="<0.urn:uuid:14B7343BF98675BB5D1335266861289@apache.org>"; start-info="text/xml";charset=UTF-8
Content-Length: 81847
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335266861287
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:14B7343BF98675BB5D1335266861289@apache.org>
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:downloadAttachmentResponse xmlns:ns1="http://www.telelogic.com/change/types"><attachmentContents><xop:Include href="cid:1.urn:uuid:14B7343BF98675BB5D1335266861290@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"></xop:Include></attachmentContents></ns1:downloadAttachmentResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335266861287
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <1.urn:uuid:14B7343BF98675BB5D1335266861290@apache.org>
��ࡱ�����������������>���� ����������������������������������������������������������������������������������������������������������������������������������������������
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335266861287--
目前,我正在考虑使用HttpWebRequest调用该服务,因为解析不容易出错。
当对此特定消息使用默认 MTOM 编码器时,它可以工作:S 现在我需要动态切换编码器?!
我终于让它工作了。基于 WCF SWA 示例,我创建了一个绑定扩展,该扩展使用 TextMessageEncodingBindingElement 作为默认值,用于在接收多部分/相关消息时使用 MtomMessageEncodingBindingElement 发送消息和回退机制。
谢谢大家。
此肥皂的格式类似于 MIME 消息,但实际上没有附件。如果您有包含附件的样本,请发布。Otehrwise,我假设tehre从来都不是附件,我建议您构建自己的消息编码器,该编码器可以简单地剥离除肥皂信封以外的所有内容。
确保操作标头(从 Java 传入)不为空,或应用 WCF 服务行为 – AddressFilterMode。
轴需要SOAPAction:foo
标头。不要问我为什么,"foo"可以是(据我所知)任何东西,无论调用的服务如何。但如果不存在,它将出错。因此,如果您将其添加到第二次尝试中,可能会解决您的问题。
YMMV,我只需要在单个客户端站点处理安讯士托管的 Java 服务,但所有这些服务都是这样。