dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.7k stars 559 forks source link

Unable to read multipart response from SOAP11 service with MTOM? #4918

Open Dawiducik opened 2 years ago

Dawiducik commented 2 years ago

Hello, we have following SOAP answer from one of the services, running SOAP 1.1 with WS Addressing:

HTTP/1.1 200 OK
X-Backside-Transport: OK OK
Connection: Keep-Alive
Transfer-Encoding: chunked
Date: Wed, 28 Sep 2022 11:40:07 GMT
X-Powered-By: Servlet/3.1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:98eb4321-4665-4970-a24d-e9bc20cd051c"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Content-Language: en-US
X-Global-Transaction-ID: a38d5ad06334329744471fad

--uuid:98eb4321-4665-4970-a24d-e9bc20cd051c
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsa="http://www.w3.org/2005/08/addressing">
... <rest of envelope>
--uuid:98eb4321-4665-4970-a24d-e9bc20cd051c--

According to this W3 documentation, this message is a valid SOAP 1.1 with multipart content.

The problem is, whether I want to read this message from client using MTOM encoder MtomMessageEncodingBindingElement, there is an exception telling me that Root MIME part must have media type 'application' and media subtype 'xop+xml', and this is true, because my Root part has MIME = text/xml.

This is the part of internal code throwing that exception.

https://github.com/dotnet/wcf/blob/d1a04680c77e5d47138c1763b42ab47295f5a1b3/src/System.Private.ServiceModel/src/Internals/System/Xml/XmlMtomReader.cs#L225-L227

Whole exception:

Unhandled exception. System.ServiceModel.CommunicationException: Error creating a reader for the MTOM message
 ---> System.Xml.XmlException: Root MIME part must have media type 'application' and media subtype 'xop+xml'.
   at System.Xml.XmlMtomReader.ReadRootContentTypeHeader(ContentTypeHeader header, Encoding[] expectedEncodings, String expectedType)
   at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize)
   at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlMtomReader.Create(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location ---
   at Program.<Main>$(String[] args) in C:\Users\
   at Program.<Main>(String[] args)

I am using .NET 6.0 with System.ServiceModel.Primitives 4.10.0 package.

Is there any way to get this working?

benken-parasoft commented 1 year ago

Your MTOM response message violates W3C spec. From https://www.w3.org/TR/soap12-mtom/#mime-serialization :

The content-type of the root part MUST be application/xop+xml

In your response, the root part has Content-Type "text/xml" which is incorrect. I doubt WCF client libraries expose options to ignore violations to the spec like this.

Could this be a bug in Apache CXF?