I was connecting to a web service hosted in PHP today when WCF threw the following error:
The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: …
I did some searching on the internet and it seems to be a known issue. Here is exactly how I solved it. I created three new classes which I have included links to download:
CustomTextMessageBindingElement.cs
CustomTextMessageEncoder.cs
CustomTextMessageEncoderFactory.cs
After adding these to your project add the following code to set the custom binding
CustomBinding binding = new CustomBinding(
new CustomTextMessageBindingElement("iso-8859-1", "text/xml", MessageVersion.Soap11),
new HttpsTransportBindingElement());
myWebService client = new myWebService();
client.Endpoint.Binding = binding;
Download code here WCF_CodeSample
Thanks to these links for the source files and answers
http://msdn.microsoft.com/en-us/library/ms751486.aspx
http://stackoverflow.com/questions/7033442/using-iso-8859-1-encoding-between-wcf-and-oracle-linux
Comments are closed.