0

I'm trying to consume a web service that uses MTOM format to upload a document. I used this custom binding:

    Dim myBinding As New CustomBinding()
    myBinding.Elements.Clear()
    myBinding.Elements.Add(New MtomMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8))
    myBinding.Elements.Add(New HttpsTransportBindingElement() With {.TransferMode = TransferMode.Streamed})

The thing is the file is uploaded just fine and I get the response from the service saying that the upload was OK, but it seems that the custombinding is unable to read the response and returns an exception:

"Error creating reader for MTOM message"

And the inner expcetion is:

"MIME part with Content-ID <a35854a.245cd7c5.5f.180a95c85a5.N7ff5>"

This is the MTOM request send to the WS that I obtained with fiddler:

--uuid:8efb8701-5bad-4205-b58a-40fe4d0d75b2+id=2
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Header>
            <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo6ss1HAFeW9PqjRwYpVfFJkAAAAAEWdHJBMAdU6HTEvorpDrFI/tlMXgYDlIsj9+kfCyhgYACQAA</VsDebuggerCausalityData>
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <altaDocument xmlns="http://www.openuri.org">
                <altaDoc xmlns="cat/gencat/justicia/cee/model/xmlbeans">
                    <identificacio>
                        <identificadorUsuari>111111111</identificadorUsuari>
                        <token>1182c59b-d1ee-0000-0000-29955741af001652108888340</token>
                    </identificacio>
                    <contingutDoc>
                        <xop:Include href="cid:http://tempuri.org/1/637877128927000384" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
                    </contingutDoc>
                    <nomFitxer>001_14_escrito prueba 1</nomFitxer>
                    <extensio>pdf</extensio>
                </altaDoc>
            </altaDocument>
        </s:Body>
    </s:Envelope>
--uuid:8efb8701-5bad-4205-b58a-40fe4d0d75b2+id=2
Content-ID: <http://tempuri.org/1/637877128927000384>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

<< more document content>>

And this is the WS response, which the custombinding is unable to properly read:

--MIME_Boundary
Content-ID: a35854a.245cd7c5.5f.180a95c85a5.N7ff5
Content-Type: application/xop+xml; type="text/xml"; charset=utf-8
Content-Transfer-Encoding: 8bit

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <S:Body>
        <w:altaDocumentResponse xmlns:w="http://www.openuri.org">
            <xb:altaDocResposta xmlns:xb="cat/gencat/justicia/cee/model/xmlbeans">
                <xb:identificadorDoc>20220509170812_3ff837ca-23cd-49b5-ad70-1c748c76a3bf</xb:identificadorDoc>
                <xb:dataFiDisponibilitat>2022-05-10T05:08:15.031+02:00</xb:dataFiDisponibilitat>
                <xb:dadesRetorn>
                    <xb:codiRetorn>0</xb:codiRetorn>
                    <xb:descRetorn>Operació efectuada correctament.</xb:descRetorn>
                </xb:dadesRetorn>
            </xb:altaDocResposta>
        </w:altaDocumentResponse>
    </S:Body>
</S:Envelope>

--MIME_Boundary--

Any ideas why I'm getting an error on the response?

I also noticed that when I get an error from the service, the custombinding I use is able to deserialize the response from the service, the response being:

--MIME_Boundary
Content-ID: <http://tempuri.org/0>
Content-Type: application/xop+xml; type="text/xml"; charset=utf-8
Content-Transfer-Encoding: 8bit

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
            <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozqpRTQoVkZMjQKdloD5UTAAAAAASJUzd7a5+EqRgnDWlWggz02OAU3BpDJMoYtfqyJl/wgACQAA</VsDebuggerCausalityData>
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
            <open:altaDocumentResponse xmlns:open="http://www.openuri.org">
                <xb1:altaDocResposta xmlns:xb1="cat/gencat/justicia/cee/model/xmlbeans">
                    <xb1:codiRetorn>OSB_ERR2</xb1:codiRetorn>
                    <xb1:descripcioRetorn>Servei de CEE no disponible en aquests moments</xb1:descripcioRetorn>
                </xb1:altaDocResposta>
            </open:altaDocumentResponse>
        </s:Body>
    </soapenv:Envelope>

--MIME_Boundary--

But what's the difference? Why this response can be processed without error but the first one isn't? The exception said that "MIME part with Content-ID <a35854a.245cd7c5.5f.180a95c85a5.N7ff5> not found", why that isn't found, but the "Content-ID: http://tempuri.org/0" doesn't produce the same exception?

starkspc
  • 11
  • 3
  • You can take a look at the answer in [this thread](https://social.msdn.microsoft.com/Forums/en-US/4cfb334b-554c-464c-9efc-6031b9fc1e93/malformed-mtom-message-at-service?forum=wcf), hope it helps you. – Lan Huang May 10 '22 at 06:27
  • I tried adding the "message.Properties.Remove(HttpRequestMessageProperty.Name)" to a MessageInspector in the "BeforeSendRequest" event, but nothing, and it doesn't even get to the AfterReceiveReply event in the MessageInspector. – starkspc May 10 '22 at 08:07
  • Maybe the problem with maxBufferSize, you can check [this thread](https://stackoverflow.com/questions/17175231/wcf-error-creating-reader-for-mtom-message) and https://stackoverflow.com/questions/69663320/wcf-net-core-create-programmatically-binding-with-mtom-and-clientcertificate. – Lan Huang May 12 '22 at 09:48
  • Sorry for the late response, I tried what's suggested in that thread but that's .NET Core and there's some things that I don't know how to apply in .NET. But in any case I changed what you said about the maxBufferSize but I keep getting the same error. – starkspc May 18 '22 at 08:30

0 Answers0