5

I have a C# WCF service running which needs to accept messages in ISO-8859-1. Everything works fine until someone sends a message containing a special character such as ä or ö.

If the characters are encoded (ä to \344 or ä) everything works fine, but the sender insists that if the message is otherwise ISO-8859-1, there should be no need for escaping.

More specifically, this works (simplified example):

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    a
  </soap:Body>
</soap:Envelope>

(but of course throws an another exception due to invalid syntax, but the transport itself is fine).

This doesn't work:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    ä
  </soap:Body>
</soap:Envelope>

And throws a bunch of cryptic error message that lead nowhere:

<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, ...</ExceptionType>
<Message>The I/O operation has been aborted because of either a thread exit or an application request</Message>
...
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, ...</ExceptionType>
<Message>An operation was attempted on a nonexistent network connection</Message>

I've tried to run the service with an empty App.config and the problem persists, so I'm pretty sure the problem is not in the way I've created the service, but rather in how WCF handles the messages. Changing the encoding to UTF-8 doesn't help either.

Any idea why a single umlaut messes up the service so catastrophically? XML is supposed to support encodings other than ASCII, so what's the deal here? Is there any changes I could do or if all hope is lost, how could I convince the sender to encode their special characters?

Peter
  • 912
  • 3
  • 11
  • 29
Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185
  • Similar problem here: http://stackoverflow.com/questions/5369462/wcf-and-custom-text-encoding-messy-business Might help. – danish Mar 04 '14 at 14:46

1 Answers1

0

The problem was not what I thought it was.

The data the customer sent us was missing the correct xml declaration:

<?xml version="1.1" encoding="ISO-8859-1"?>

With this, the service worked properly.

But the exceptions I got were caused by the program we tested the connection ourselves with. The program was WebServiceStudio, and it failed completely when we tried to send special characters (specifically ä) through it: the body of the message was absent completely when inspected with WireShark.

So, initially we thought that the customer was having the same problem as us, but when we noticed that our tests were failing, the real reason was found quickly, which was the missing XML declaration from the SOAP message.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185