Search code examples
wcfwindows-8mtom

mtomMessageEncoding in Windows Store Apps


I have written the following program in Windows Store Apps.

CustomBinding b = new CustomBinding() ;
TextMessageEncodingBindingElement t = new TextMessageEncodingBindingElement();
HttpTransportBindingElement h = new HttpTransportBindingElement();          
b.Elements.Add(t);
b.Elements.Add(h);

MyService client = new MyService(b, new EndpointAddress("http://localhost:8080/"));

var request = ...;
var response = client.Service000(request);

In Service000, request message is Utf-8 encoding, but response message is Mtom Encoding like following.

mime-version: 1.0
Content-Type: Multipart/Related;
boundary=4aa7d814-adc1-47a2-8e1c-07585b9892a4;
type=application/xop+xml;
start=”<14629f74-2047-436c-8046-5cac76d280fc@uuid>”;
startinfo=”application/soap+xml”

--4aa7d814-adc1-47a2-8e1c-07585b9892a4
Content-Type: application/xop+xml; type="application/soap+xml"
                charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <14629f74-2047-436c-8046-5cac76d280fc@uuid>

<soap:Envelope>
....
</soap:Envelope>

--4aa7d814-adc1-47a2-8e1c-07585b9892a4
Content-Type: image/jpeg;
Content-Transfer-Encoding: binary
Content-ID: <1c696bd7-005a-48d9-9ee9-9adca11f8892@uuid>

Binary Scan Data
--4aa7d814-adc1-47a2-8e1c-07585b9892a4--

I want to process response message by MtomMwssageEncodeingBindingElement. But WinRT doesn't support MtomMwssageEncodeingBindingElement. Is there any way to process Mtom Enconding message?


Solution

  • Not easily. As you noted, the MTOM message encoding isn't supported by the WinRT .NET subset, so you cannot use it. If you control the service, you should consider adding a new endpoint with a binding that is supported by WinRT (such as BasicHttpBinding). If not, then you'd need to create a custom encoder which knows how to parse MTOM messages, which is not a trivial task.