Question

I have a MTOM response on the disk and I am trying to load and parse the response. While creating an MTOM reader I keep getting the error.

Invalid MIME content-type header encountered on read.

Is this a bug or does the header for content-type really means that Visual Studio cannot understand the content type?

MIME-Version: 1.0
Content-Type: Multipart/Related;boundary=DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM;
    type="application/xop+xml";
    start="<DeltaSyncMTOMFetchResponse@mail.services.live.com>";

    --DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
    content-transfer-encoding: binary
    content-type: application/xop+xml; charset=utf-8; type="application/xop+xml"
    content-id: <DeltaSyncMTOMFetchResponse@mail.services.live.com>

    <ItemOperations xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:B="HMMAIL:" xmlns:D="HMSYNC:" xmlns="ItemOperations:"><Status>1</Status><Responses><Fetch><ServerId>E631966A-9439-11E1-8E7B-00215AD9A7B8</ServerId><Status>1</Status><Message><xop:Include href="cid:1.634715231374437235@example.org" /></Message></Fetch></Responses></ItemOperations>
    --DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
    content-transfer-encoding: binary
    content-type: application/octet-stream
    content-id: <1.634715231374437235@example.org>

Here is the simple code to create the MTOM reader.

XmlDictionaryReader mtomReader = XmlDictionaryReader.CreateMtomReader
            (
             fStream,
             Encoding.UTF8,
             XmlDictionaryReaderQuotas.Max
            );
Was it helpful?

Solution

There are several problems in your data:

  • You need to encode boundary string in your Content-Type header because it contains ? character.
  • Lines 5 to end are indented - you need to remove the leading spaces
  • You are missing the ending boundary string

Here is the modified content that worked for me:

MIME-Version: 1.0
Content-Type: Multipart/Related;boundary="DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM"";
    type="application/xop+xml"";
    start="<DeltaSyncMTOMFetchResponse@mail.services.live.com>"";

--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/xop+xml; charset=utf-8; type="application/xop+xml""
content-id: <DeltaSyncMTOMFetchResponse@mail.services.live.com>

<ItemOperations xmlns:xop="http://www.w3.org/2004/08/xop/include"" xmlns:B=""HMMAIL:"" xmlns:D=""HMSYNC:"" xmlns=""ItemOperations:""><Status>1</Status><Responses><Fetch><ServerId>E631966A-9439-11E1-8E7B-00215AD9A7B8</ServerId><Status>1</Status><Message><xop:Include href=""cid:1.634715231374437235@example.org"" /></Message></Fetch></Responses></ItemOperations>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/octet-stream
content-id: <1.634715231374437235@example.org>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM--
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top