SoapHttpClientProtocol receives unexpected content type

2.2k views Asked by At

I created a C# proxy class via wsdl.exe from a WSDL-URL. I'm using this proxy class in the context of a web app which I do not control (so there's no way to change a web.conf or similar). I'm also unable to change anything in the web service that I'm talking to.

When calling the web service, I receive the following exception:

Client found response content type of 'multipart/related; type="application/xop+xml"; 
boundary="uuid:5c314128-0dc0-4cad-9b1a-dc4a3e5917bb"; start="<[email protected]>"; 
start-info="application/soap+xml"', but expected 'application/soap+xml'.

From what I've read, this is a problem with MTOM being used by the web service. Now I'm trying to tell my class to accept MTOM, but all I've found is configuration in the web.conf.

The proxy class is derived from SoapHttpClientProtocol and looks like this (relevant parts):

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]    
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "myrequestSoapBinding", Namespace = "http://namespace.of.company.of.webservice/")]
public class myrequest : System.Web.Services.Protocols.SoapHttpClientProtocol
{
    public myrequest(string url)
    {
        this.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;            
        this.Url = url;
    }

    [return: System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "base64Binary")]
    public byte[] getDocuments([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "base64Binary")] byte[] input)
    {
        try
        {
            object[] results = this.Invoke("getDocuments", new object[] {
                input});
            return ((byte[])(results[0]));
        }
        catch (Exception ex)
        {
            var realResponse = StripResponse(ex.Message);
            return Encoding.UTF8.GetBytes(realResponse.ToString());
        }
    }
}

The try ... catch in getDocuments is a hacky workaround that gets the 'real' service response out of the exception Message - which is not really how I want to implement this.

So my question is: Is there a way to change the binding in the proxy class to accept MTOM responses?

1

There are 1 answers

0
Steve Lillis On

From the small amount of research I've done in an effort to help, it appears that if you did have access to the web config (which I know you don't) and you turned on MTOM then Visual Studio would generate two proxy classes:

  1. A standard one that derives from SoapHttpClientProtocol, and;
  2. A WSE one with "Wse" appended to the class name that derives from Microsoft.Web.Services3.WebServicesClientProtocol

It is the WebServicesClientProtocol implementation that is able to accept MTOM. To have WSDL create a proxy that derives from WebServicesClientProtocol, follow the Note at the top of this MSDN article.

Hopefully this will resolve the issue.