简体   繁体   中英

WCF unable to parse Java soap response

I have this response from a Java web service:

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

The exception from WCF is telling me The data at the root level is invalid. Line 1, position 1. The data at the root level is invalid. Line 1, position 1.

My app.config is as following:

<customBinding>
  <binding>
    <!--<messageModifier />-->
    <!--<mtomMessageEncoding messageVersion="Soap11" writeEncoding="utf-8" />-->
    <textMessageEncoding writeEncoding="utf-8" messageVersion="Soap11"   />
    <httpsTransport
      requireClientCertificate="false"
      transferMode="Buffered" />
  </binding>
</customBinding>

As you can see I already tried different settings like mtom/text encodig, soap11/soap12 for message version, buffered and responseStreamed for transferMode. I'm kind of stuck. When I strip some of the response with Fiddler I got it working:

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>

Am I missing something? Is there a magic combination of config settings I need?

I also tried bot the IClientMessageFormatter and the IClientMessageInspector but they both seem to be too high in the stack because WCF already fails with the ProtocolException telling The data at the root level is invalid. Line 1, position 1. The data at the root level is invalid. Line 1, position 1. .

I hooked in the ChannelMessageInterceptor from the WCF sample . I thought I got that working but now I'm getting exceptions from the java service:

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

At least it is telling me they're using Axis? I've also seen exception messages telling me the content type of the response doesn't match the type from the binding, but I cannot reproduce them at this time.

It looks a lot like this question. I also tried the WCF Soap With Attachments Encoder but it also keeps nagging the Data at the root level is invalid. Line 1, position 1. Data at the root level is invalid. Line 1, position 1. (but now directly inside a XmlException rather than a ProtocolException).

Update I have the WCF SWA working!

An example message including an attachment:

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

At the moment I'm thinking about invoking the service with a HttpWebRequest because the parsing is much less error prone.

When using the default MTOM Encoder for this specific message it works :S Now I need to dynamically switch encoders?!

I finally got it working. Based on the WCF SWA sample I created a binding extension which uses the TextMessageEncodingBindingElement as default and for sending messages and a fallback mechanism using the MtomMessageEncodingBindingElement when receiving multipart/related messages.

Thank you all.

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

This soap is formatted like a mime message but in practice there are not attachments. If you have a sample that does contain attachment please publish. Otehrwise I assume tehre are never attachments and I would advise you build your own message encoder that simply strips everything except the soap envelope.

Axis requires the SOAPAction:foo header. Don't ask me why, and 'foo' can be (as far as I can tell) anything, regardless of the service being invoked. But it will error if that's not there. So if you add that to your second try that might solve your problem.

YMMV, I've only had to deal with Axis-hosted Java services at a single client site, but ALL of them were like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM