I'm a newbie in WFC and, so far, only have done client code to call POX web services.
I've been using a textMessageEncoding binding extension with a message version of None and a write encoding of utf-8 and all has been running fine.
Well, until I needed to call a service in iso-8859-1 encoding. Then I started getting a ProtocolException:
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.
Bruno directed me to a sample that looked promising. The sample works fine because it's using the same binding extension in the server and in the client.
When I tried to use the customTextMessageBinding from the sample, I got this nice ProtocolException:
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=iso-8859-1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
Looks kind of funny, doesn't it?
It comes down to the fact that the base MessageEncoder class doing a string comparison on the content type.
To solve this, I've overriden the IsContentTypeSupported method and added an additional validadion when the base validation fails. This new validation only checks for the media type of the response and lets the XmlReader handle the encoding.
public override bool IsContentTypeSupported(string contentType)
if (contentType.Length == this.MediaType.Length)
return contentType.Equals(this.MediaType, StringComparison.OrdinalIgnoreCase);
if (contentType.StartsWith(this.MediaType, StringComparison.OrdinalIgnoreCase)
&& (contentType[this.MediaType.Length] == ';'))
Since this seems to be happening in Orcas too, I've added a comment to the sample documentation and opened an issue. Vote on them.