WCF SOAP 1.2 service expecting SOAP 1.1 content type

wcf

I'm building a WCF web service that requires interop with non-WCF clients (in fact, there will be no WCF clients).

I've already written a WSDL using SOAP 1.2 (as per this example). I've validated the WSDL and have used this file (not the WSDL generated by WCF, which is superficially different) to create a soapUI test project.

I have a requirement that the web service will support SOAP 1.2, so I can't just fall back to SOAP 1.1 (which worked just fine in an early prototype).

I've used WSCF.blue to generate my WCF service, interface, and data contract classes. Everything compiles nicely and the endpoint is exposed if I hit the WCF service in my browser. All seems well with the world.

When I try to call a method from soapUi I get the following response from the server (as visible from soapUI):

HTTP/1.1 415 Cannot process the message because the content type 
'application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"' 
was not the expected type 'text/xml; charset=utf-8'.
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 30 Apr 2012 08:15:29 GMT
Content-Length: 0

(Actual method names and namespaces have been manually changed for the purposes of this question. Any typos in namespace are not errors in my code – just an oversight in typing up this question)

I know that SOAP 1.1 specifies that the content type must be text/xml. SOAP 1.2 requires application/soap+xml.

My raw request (as per soapUI):

POST http://localhost/MyWs.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
               xmlns:ns="http://tempuri.org">
   <soap:Header/>
   <soap:Body>
      <ns:fetchMyThingRequest attribute1="1" attribute2="10">
      </ns:fetchMyThingRequest>
   </soap:Body>
</soap:Envelope>

From this response, it tells me that my request is properly formed – it's a SOAP 1.2 request with the correct content type. My WCF service, however, does not expect this content type, which I assume means I have not configured it correctly and it still thinks it's a SOAP 1.1 web service.

Minimal Web.config, as per this blog post:

<system.serviceModel>
  <services>
    <service name="MyNamespace.MyPort">
      <endpoint address="" binding="customBinding" bindingConfiguration="httpSoap12" contract="IWsPort12" />
    </service>
  </services>

  <bindings>
    <customBinding>
      <binding name="httpSoap12">
        <textMessageEncoding messageVersion="Soap12" />
        <httpTransport />
      </binding>
    </customBinding>
  </bindings>
</system.serviceModel>

A snippet of the service contract:

[ServiceContract(Namespace = "http://tempuri.org")]
public interface IWsPort
{
  [OperationContract(Action = "http://tempuri.org/FetchMyThing")]
  [FaultContract(typeof(WsFault), Action = "http://tempuri.org/FetchMyThing", Name = "fetchMyThingFault")]
  [XmlSerializerFormat(SupportFaults = true)]
  FetchMyThingResponse FetchMyThing(FetchMyThingRequest request);
}

I enabled service tracing for my WCF service and see the following exception that seems to confirm my hypothesis:

Activity: Listen at 'http://mycomputer/MyWs.svc
<Exception>
  <ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
  <Message>Content Type application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing" was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched.   
  </Message>
(erroneous detail snipped)
</Exception>

So, my contract and service bindings are probably mismatched, if this message is to believed, but from what I understand of WCF my configuration (or at least the intent behind it) is correct.

Does anyone have any ideas as to what's wrong with my configuration?

Best Answer

The only thing I can think with it is that because you've not specified a binding in a lot of detail, and its using HTTP (as per this: "Listen at 'http://mycomputer/MyWs.svc'") then is it using the default (i.e. basicHttpBinding) for this, which is creating the mismatch?

Related Topic