WCF无法解析Java的SOAP响应

问题描述:

我有一个Java Web服务这样的响应:WCF无法解析Java的SOAP响应

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:[email protected]> 
<?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.

我的app.config是如下:

<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消息版本,缓冲和responseStreamed transferMode。我有点卡住了。当我用Fiddler去掉一些响应时,我得到了它的工作:

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> 

我是否错过了什么?是否有我需要的配置设置的魔术组合?

我也尝试过bot IClientMessageFormatter和IClientMessageInspector,但它们在堆栈中似乎都太高,因为WCF已经失败,并且ProtocolException告诉The data at the root level is invalid. Line 1, position 1.

我迷上了WCF sample的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:[email protected]>"; 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:[email protected]> 

<?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-- 

至少它告诉我,他们正在使用Axis?我也看到异常消息告诉我响应的内容类型与绑定中的类型不匹配,但我现在不能再现它们。

它看起来很像this问题。我也尝试了WCF Soap With Attachments Encoder,但它也一直唠叨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:[email protected]>"; 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:[email protected]> 

<?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:[email protected]" 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:[email protected]> 

��ࡱ�����������������>���� ���������������������������������������������������������������������������������������������������������������������������������������������� 
--MIMEBoundaryurn_uuid_14B7343BF98675BB5D1335266861287-- 

在我正想着用的HttpWebRequest调用该服务的时刻,因为解析是非常不容易出错。

当使用默认的MTOM编码器为这个特定的消息它的作品:S现在我需要动态切换编码器?

我终于搞定了。基于WCF SWA示例,我创建了一个绑定扩展,它在接收多部分/相关消息时使用TextMessageEncodingBindingElement作为默认值,并使用MtomMessageEncodingBindingElement发送消息和回退机制。

谢谢大家。

这个肥皂被格式化为一个mime消息,但实际上没有附件。如果您有包含附件的样本,请发布。 Otehrwise我认为这是从来没有附件,我会建议你建立你自己的消息编码器,只需剥去除肥皂信封外的所有东西。

+0

如何对附件进行注册?剥离似乎为我现在正在使用的操作做好了工作,但我不确定这是否将来可以证明... – riezebosch 2012-04-24 09:05:24

+0

如果请求的结构是固定的,它将始终在Content-ID之后。如果邮件符合某些标准(例如swa),那么wcf swa应该可以工作。要确定这一点,我们需要一个附件的例子 – 2012-04-24 10:29:43

+0

我用一个例子更新了这个问题。 – riezebosch 2012-04-24 11:47:54

确保Action Header(从Java传入)不为空,或者应用WCF ServiceBehavior - AddressFilterMode。

轴需要SOAPAction:foo标题。不要问我为什么,'foo'可以(据我所知)任何东西,不管被调用的服务是什么。但如果不存在,它将会出错。因此,如果您将其添加到第二次尝试中,那可能会解决您的问题。

YMMV,我只需要在一个客户端网站上处理Axis托管的Java服务,但他们都是这样的。