.NET Webservice = 代理对无效

发布于 2024-08-14 18:12:28 字数 645 浏览 1 评论 0原文

调用 Web 服务时出现以下抛出错误。除了有人问同样的问题之外,谷歌搜索没有任何结果。

Server was unable to process request. ---> The surrogate pair (0xD860, 0x27) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate character (0xDC00 - 0xDFFF)."} 
System.Exception {System.Web.Services.Protocols.SoapException

Web 服务通过运行视图并打开数据集并读取数据并将其作为格式化 XML 返回,从视图中返回一系列简单的文本字段。

编辑

能够使用以下正则表达式解决此问题,该正则表达式删除恰好是 MSWord/Excel 字符的坏字符

string re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
return Regex.Replace(text, re, string.Empty);

Getting the following thrown error when calling a web service. Have googled without any results other then people asking the same question.

Server was unable to process request. ---> The surrogate pair (0xD860, 0x27) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate character (0xDC00 - 0xDFFF)."} 
System.Exception {System.Web.Services.Protocols.SoapException

The web service returns a series of simple text fields from a view by running the view and opening a dataset and reading in the data and returning it as formatted XML.

EDIT

Was able to resolve this using the following regex which strips out the bad characters which happened to be MSWord/Excel characters

string re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
return Regex.Replace(text, re, string.Empty);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2024-08-21 18:12:28

可能发生的情况是:

  • XML 文件包含字节 ED A1 A0 27。根据 chardet 的说法,这很可能是用 IBM866 编码的 эба'
  • 但它缺少 encoding 声明,因此解析器假定它是 UTF-8。
  • 文本被解码为 UTF-16 字符串 D860 0027。
  • 由于未配对的代理项 D860,该字符串不是有效的 UTF-16,因此您会得到异常。

What might be happening is that:

  • The XML file contains the bytes ED A1 A0 27. According to chardet, this was most likely intended to be эба' encoded in IBM866.
  • But it lacks an encoding declaration, so the parser assumes that it's UTF-8.
  • The text gets decoded into the UTF-16 string D860 0027.
  • This string is not valid UTF-16 because of the unpaired surrogate D860, so you get the exception.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文