简体   繁体   English

特殊字符的WCF服务失败

[英]WCF service fails on special characters

I have a C# WCF service running which needs to accept messages in ISO-8859-1. 我有一个C#WCF服务运行,需要接受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. 如果字符是编码的( ä\\344ä )一切正常,但发件人坚持认为如果消息是ISO-8859-1,则不需要转义。

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. 我试图使用空的App.config运行该服务并且问题仍然存在,所以我很确定问题不在于我创建服务的方式,而在于WCF如何处理消息。 Changing the encoding to UTF-8 doesn't help either. 将编码更改为UTF-8也无济于事。

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? XML应该支持除ASCII之外的编码,那么这里的交易是什么? Is there any changes I could do or if all hope is lost, how could I convince the sender to encode their special characters? 我可以做任何改变,或者如果所有的希望都失去了,我怎么能说服发件人编码他们的特殊字符?

The problem was not what I thought it was. 问题不是我想的那样。

The data the customer sent us was missing the correct xml declaration: 客户发送给我们的数据缺少正确的xml声明:

<?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. 该程序是WebServiceStudio,当我们尝试通过它发送特殊字符(特别是ä )时它完全失败:当使用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. 所以,最初我们认为客户遇到了与我们相同的问题,但是当我们注意到我们的测试失败时,真正的原因被迅速发现,这是SOAP消息中缺少的XML声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM