NET Web服务=代理对无效 [英] .NET Webservice = The surrogate pair is invalid

查看:158
本文介绍了NET Web服务=代理对无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用Web服务时,遇到了以下抛出的错误。用Google搜索没有其他任何结果的话,人问同样的问题。

 服务器无法处理请求。 --->该代理对(0xD860,0x27)是无效的。高代理字符(0xD800  -  0xDBFF)必须始终搭配低代理角色。(0xDC00  -  0xDFFF)}
System.Exception的{System.Web.Services.Protocols.SoapException
 

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

修改

之所以能够这样使用下面的正则表达式剥离了不良字符,碰巧的MSWord / Excel中的字符来解决

 字符串重= @[^ \ X09 \ X0A \ X0D \ x20- \ xD7FF \ xE000- \ xFFFD \ 10000倍,x10FFFF];
返回Regex.Replace(文字,重,的String.Empty);
 

解决方案

可能发生的事是:

  • 在XML文件中包含的字节ED A1 A0 27. chardet的,这是最有可能的意图是эба连接codeD在IBM866。
  • 但它缺乏一个编码声明,因此解析器假定它是UTF-8。
  • 在文本得到德codeD插入UTF-16字符串D860 0027。
  • 在此字符串是不是因为配对的替代D860的有效的UTF-16,所以你得到的异常。

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);

解决方案

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.

这篇关于NET Web服务=代理对无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆