Search code examples
c#.netwcfwcf-client

WCF "Content Type was not supported" error


When I am trying to connect to my WCFService the following error occurred.

Content Type text/xml; charset=utf-8 was not supported by service http://localhost:1978/Service1.svc. The client and service bindings may be mismatched.

My service code is :

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(string fName, string lName);
    }
}

And in the client form I am calling this service as follows:

endPointAddr = "http://localhost:1978/Service1.svc";

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.TransferMode = TransferMode.Buffered;

EndpointAddress endpointAddress = new EndpointAddress(endPointAddr);

Append("Attempt to connect to: " + endPointAddr);

IService1 proxy = ChannelFactory<IService1>.CreateChannel(httpBinding, endpointAddress);

using (proxy as IDisposable)
{
    string strNew=proxy.GetData(textBox2.Text, textBox1.Text) ;
}

I am stuck on that error, if anybody knows please help.


Solution

  • I suspect that your WCF service has a binding of WSHttpBinding or similar - you need to change the client binding (which is currently using BasicHttpBinding) accordingly to make it work...