Liedman
Liedman

Reputation: 10329

Why doesn't WCF support other encodings than UTF-8 and UTF-16 by default?

We have some issues with a WCF SOAP service that we publish, and is consumed by one of our customers. The issue is that the customer makes SOAP requests encoded as ISO-8859-1, which results in the error message:

HTTP/1.1 415 Cannot process the message because the content type 'text/xml;charset=iso-8859-1' was not the expected type 'text/xml; charset=utf-8'.

Apparently, WCF only supports UTF-8 and UTF-16 big endian, according to http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx. The problem is also discussed in these questions on SO:

While I agree that unicode is preferred, I'm not in a position to force our customer to change their client, so I will have to fix our service.

It bugs me that I need to put >150 lines of code written by some MSDN author into my project - I can't maintain that code or take responsibility for it. I've also spent quite some time to Google for solutions and try to understand them, which I feel is a waste of time for something that could be handled out of the box by WCF.

My question is: is there any good reason for Microsoft to implement WCF this way? Is there a technical reason why SOAP shouldn't use ISO-8859-1? To me, this seems to break Postel's law, rejecting messages that can really be handled by almost any XML parser out there.

Upvotes: 2

Views: 4596

Answers (2)

rkawano
rkawano

Reputation: 2503

One workaround is consume the service in an "old times" way using the HttpWebRequest class, as described here. You will have to deal with pure Xml to make requests and other cool things, but works fine!

Upvotes: 0

Peter O.
Peter O.

Reputation: 32878

Apparently, this is allowed in the SOAP 1.2 specification, see section 4.2:

A binding, if using an XML serialization of the XML infoset, MAY mandate that a particular character encoding or set of encodings be used.

In this case, WCF chooses to support only UTF-8 and UTF-16, not other encodings.

Upvotes: 2

Related Questions