Click here to Skip to main content
15,881,812 members
Articles / Programming Languages / C#
Tip/Trick

Solution to WSE839 error for WSE3 clients needing support both MTOM and non-MTOM responses

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
6 Jun 2010CPOL 18K   2  
Sometimes you need a WSE3 client to send an MTOM-encoded request, but accept either an MTOM or non-MTOM response. While the WSE3 server classes support "MTOM optional" the client does not. Here's a quick solution to the problem.Assume you have generated your WSE3 web service proxy class....
Sometimes you need a WSE3 client to send an MTOM-encoded request, but accept either an MTOM or non-MTOM response. While the WSE3 server classes support "MTOM optional", the client does not. Here's a quick solution to the problem.

Assume you have generated your WSE3 web service proxy class. Normally you would set the RequireMtom property true on that object and make the call; but WSE3 then requires an MTOM-encoded response. With this trick, you can accept either.

Define a new class that inherits from your WSE3 proxy object with a single override method GetWebResponse:

 using System.Net;
class MyNewWebServiceProxy : MyWSE3GeneratedProxyClass
{
    protected override WebResponse GetWebResponse(WebRequest request)
    {
        WebResponse response = base.GetWebResponse(request);
        // if the response is non-MTOM like a SOAP fault, tell the proxy
        //   we don't really need MTOM
        if (response.Headers[HttpResponseHeader.ContentType].ToLower().StartsWith("text/xml"))
        {
            this.RequireMtom = false;
        }

        return response;
    }
}


Now instead of creating an instance of the WSE3 proxy, create an instance of this one and set the RequireMtom true before calling your MTOM web method.

The gotcha is you need to remember to reset the RequireMtom on the proxy back to true before making another call on the same proxy instance if the next method call also needs MTOM.

-- Darren DeLoach

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --