WcfCoreMtomEncoder icon indicating copy to clipboard operation
WcfCoreMtomEncoder copied to clipboard

Error with MTOM encoding .net core 2.2

Open yalin78 opened this issue 4 years ago • 5 comments

I am consuming one of our third party vendor's soap and they are using MTOM encoding. My application is using .net core 2.2 and here is the code i am using but i am receiving excepiton.

var encoding = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement()); var transport = new HttpTransportBindingElement(); var customBinding = new CustomBinding(encoding, transport);

        EndpointAddress address =
                      new EndpointAddress("http://zzz.xxx.com:8976/dfdaf/2019.01/filemanagement?wsdl");
        FileManagement.FileManagementServiceClient client = new FileManagementServiceClient(customBinding, address);

But i am receiving following exception

The content type text/xml; charset=UTF-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:

ProtocolException: The content type text/xml; charset=UTF-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:

yalin78 avatar May 22 '20 21:05 yalin78

Any updates to this?

int3rrupt avatar Jun 30 '20 01:06 int3rrupt

Nope.

yalin78 avatar Dec 07 '20 17:12 yalin78

I was able to fix the error above by using MessageVersion.Soap11 below:

                var textMessageEncodingBindingElement = new TextMessageEncodingBindingElement
                {
                    MessageVersion = MessageVersion.Soap11,   // without this, you'll get: Content Type application/soap+xml; charset=utf-8 was not supported by service
                    ReaderQuotas =
                    {
                        // TODO: these settings are a guess
                        MaxStringContentLength = 50000000,
                        MaxBytesPerRead = 50000000,
                        // other settings here
                    }
                };

toweldaddy avatar Dec 08 '20 23:12 toweldaddy

I've a similar problem, this is my code

var readerQuotas = new XmlDictionaryReaderQuotas
            {
                MaxDepth = 32,
                MaxStringContentLength = 8388608,
                MaxArrayLength = 16384,
                MaxBytesPerRead = 4096,
                MaxNameTableCharCount = 16384
            };

var encoding = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement()
                {
                    MessageVersion = MessageVersion.Soap11,
                    //MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None),
                    ReaderQuotas = readerQuotas
                });

                var transport = new HttpTransportBindingElement()
                {
                    TransferMode = TransferMode.Streamed,
                    MaxBufferSize = 2147483647,
                    MaxReceivedMessageSize = 2147483647,
                };

                var customBinding = new CustomBinding(encoding, transport);

                DeliveryService engage = new DeliveryServiceClient(customBinding, address);

                resp = engage.deliverDocument(documentRequest);

And here there is the error message,

One or more errors occurred. (Unexpected end of MIME multipart stream. MIME multipart message is not complete.)

I tried a lot of configs but I don't where is the problem,

Shumaister avatar May 05 '21 21:05 Shumaister

This is likely an issue with how the 3rd party service is handling the SOAP response. In order to investigate further, I would need some more information about what the service is returning exactly. Are you able to create a MTOM soap server that reproduces the issue? or are you able to capture the response to troubleshoot?

lennykean avatar May 06 '21 19:05 lennykean