WCF Unicode UrlEncoded Get 不太好

发布于 2024-08-05 20:11:39 字数 527 浏览 5 评论 0原文

我有一个 RESTful WCF 服务,它接受带有 Unicode 编码的 url 的 GET 动词。当我在服务器上获取数据时,Unicode 字符被奇怪地翻译为小框。

为了将 Unicode UrlEncoded Gets 转换为漂亮的字符串,我是否必须告诉服务合约执行某些操作?

这是我的合同:

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/Document/{Fragment}", RequestFormat = WebMessageFormat.Xml)]
Message GetDocumentFromSearchResult(string Fragment);

这是我传入的 unicode 示例: %FF%FE%22%00O%FF%FE%20%00King%FF%FE%20%00of%FF

我得到“King”和“of”,但其余的字符串都是小方块。

应该是解码问题??

I have a RESTful WCF service which accepts GET verbs with Unicode encoded urls. The Unicode characters are translated as little boxes strangely when I get the data on the server.

Is there something I have to tell the service contract to do in order to get Unicode UrlEncoded Gets to translate into nice strings?

Here's my contract:

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/Document/{Fragment}", RequestFormat = WebMessageFormat.Xml)]
Message GetDocumentFromSearchResult(string Fragment);

Here's a sample of the unicode I pass in:
%FF%FE%22%00O%FF%FE%20%00King%FF%FE%20%00of%FF

I get "King" and "of" ok, but the rest are little of the string are little squares.

Gotta be an decoding issue ??

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

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

发布评论

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

评论(2

离旧人 2024-08-12 20:11:39

您传递的内容看起来很奇怪:它似乎包含带有字节顺序标记的“字符UTF-16”。这几乎肯定是一个问题,所以它看起来更像是您的编码问题通常

,UTF-8 用于 URL,因为这更适合协议(无需转义纯 ASCII 中的所有 NUL 字节)这可能是您的服务所期望的,因此它不会。 t 正确解码(因为 %FF%FE 不是有效的 UTF-8)。

What you are passing in looks strange: it appears to contain UTF-16 for the " character with Byte Order Marks. This is almost certainly a problem, so it looks more like an issue with your encoding of the input.

Usually, UTF-8 is used for URLs, as this fits much better with the protocol (no need to escape all of the NUL bytes in pure ASCII). This is likely to be what your service is expecting, so it doesn't decode correctly (as %FF%FE is not valid UTF-8).

寄居者 2024-08-12 20:11:39

使用 Fragment[i] 检查字符以查看实际字符是什么。这将删除调试器或其他输出方法可能向您显示的变量。

Examine the characters using Fragment[i] to see what the actual characters are. That will remove the variable of what the Debugger or other output method may be showing you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文