Sunday, 28 March 2010

Content-Type-text-xml-charset-utf-8-was-not-supported-by-service-The-client-and-service-bindings-may-be-mismatched

I'm currently building a WCF web service and as we all know, the URL for the web service is stored in the web.config file, and I knew that when I came to deploy it to the live server, the binding would fail. Yes, I know I could publish the web service to the live server and then Add a reference in VStudio, but I like to put the test and live server URLs in the config file.
Anyway, I attempted to do the following in code, but I kept getting the error message: Content Type text/xml; charset=utf-8 was not supported by service The client and service bindings may be mismatched. And the code that caused the error was as follows:
System.ServiceModel.EndpointAddress address = new System.ServiceModel.EndpointAddress("");
InternalWebService.InternalWebServiceClient wService = new InternalWebService.InternalWebServiceClient(new System.ServiceModel.HttpBinding(), address);
Not exactly the most verbose error message in the world, so I tried a few things but they didn't work, so I started to look at the bindings, as this was perhaps the most likely culprit.  I looked in the web.config file and saw the following section:
<client>
<endpoint address=""
 
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMMDInternalWebService"
 
contract="MMDInternalWebService.IInternalWebService" name="WSHttpBinding_IInternalWebService">
So I scratch my head for a bit and started to think, hang on, wsHttpBinding, I’ve never seen that before.  So I used intellisense and found that if you type System.ServiceMode.wshttpbinding, a new class appears.  After a bit of googling, I found that HttpBinding, is used in Soap 1.1, but Soap 1.2 uses wshttpbinding().  Anyway, I wacked in the code and hey presto, the code started to call my web service.

No comments:

Post a Comment