c# - WCF 无法解析 Java Soap 响应

标签 c# java wcf web-services axis

我从 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.

我的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 encodeg、soap11/soap12 用于消息版本、buffered 和 responseStreamed 用于传输模式。我有点卡住了。当我用 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>

我错过了什么吗?是否有我需要的配置设置的神奇组合?

我还尝试了 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: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--

至少它告诉我他们正在使用 Axis?我还看到异常消息告诉我响应的内容类型与绑定(bind)中的类型不匹配,但目前我无法重现它们。

它看起来很像 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: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 示例,我创建了一个绑定(bind)扩展,它使用 TextMessageEncodingBindingElement 作为默认值并用于发送消息,并在接收多部分/相关消息时使用 MtomMessageEncodingBindingElement 进行回退机制。

谢谢大家。

最佳答案

此肥皂剧的格式类似于 mime 消息,但实际上没有附件。如果您有包含附件的示例,请发布。另外,我认为这些都不是附件,我建议您构建自己的消息编码器,该编码器可以简单地剥离除肥皂信封之外的所有内容。

关于c# - WCF 无法解析 Java Soap 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10282803/

相关文章:

c# - Linq:IEnumerable 上的扩展方法,可在执行选择时自动执行空值检查

java - 如何在 android 中创建这个嵌套的 JSON 对象并在 c# 中对其进行解码?

WCF自动化部署

c# - 从 WPF/XBAP 应用程序检测网络连接?

c# - EditItemTemplate 中 AJAX CascadingDropDown 和 DropDownList SelectedValue 的问题

c# - 流利的 NHibernate : Cascade delete from one side only on Many-to-Many relationship

c# - 创建不干扰 WPF 窗口的单独线程 MessageBox 的最佳方法?

java - 为什么在 swift 和 java 中右移运算符会得到不同的结果

java - 使用 Apache Jena 查询 Wikipedia RDF 文件(Turtle 格式)

java - 通知单线程 : notify, notifyAll or concurrent.locks.Condition?