Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service using basicHttpBinding is still sending content type "text/xml"

Tags:

soap

wcf

I am writing a WCF service, running on IIS, and I have a customer whose client can only talk SOAP 1.1.

Among other things, they need the content type to be "application/soap+xml; charset=utf-8". My WCF service is sending "text/xml; charset=utf-8".

The customer who's trying to write the client forwarded me an error message:

HTTP 415: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8

Browsing around the net, I found a number of blog pages like this: WCF Error - The request failed with HTTP status 415.

Which made me think that switching from wsHttpBinding to basicHttpBinding would fix this. So I changed the binding in the web.config, and modified my own test client to explicitly create an endpoint with a BasicHttpBinding. And that all worked fine, in my own tests (both running the service in Visual Studio's Dev Server, and running it in IIS7 on my own machine, and running it in IIS6 on one of our test servers.)

But before I gave the customer a head's up, and asked them to see if my changes would work for them, I fired up Fiddler to eavesdrop on the actual traffic.

And according to Fiddler, I'm still sending "text/xml; charset=utf-8".

So, how do I fix that?

<system.serviceModel>
    <services>
        <service behaviorConfiguration="myBehavior" name="myName">
            <endpoint 
                    address=""
                    binding="basicHttpBinding" 
                    behaviorConfiguration="flatWsdlFileEndpointBehavior" 
                    bindingNamespace="http://myNamespace"
                    contract="myContract">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="myBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="flatWsdlFileEndpointBehavior">
                <wsdlExtensions location="myUrl" singleFile="true" />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
        </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <extensions>
        <behaviorExtensions>
            <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </behaviorExtensions>
    </extensions>
</system.serviceModel>
like image 519
Jeff Dege Avatar asked Nov 10 '11 22:11

Jeff Dege


1 Answers

So do they need SOAP 1.1 or application/soap+xml; charset=utf-8? Because SOAP 1.1 specification says that the request must have text/xml as the media type. application/soap+xml is media type for SOAP 1.2. Forcing WCF to use SOAP 1.1 with application/soap+xml (= invalid SOAP) would require bigger changes than changing the binding. You will need some custom message encoder or perhaps transport channel.

like image 54
Ladislav Mrnka Avatar answered Sep 20 '22 23:09

Ladislav Mrnka