WCF 和自定义文本编码 - 混乱的业务

发布于 2024-10-23 23:42:43 字数 932 浏览 6 评论 0原文

我这里有一个非常奇怪的 WCF 问题...

我们正在连接到一个蹩脚的第三方 Web 服务;甚至让它继续下去也是一场噩梦,我们必须创建一个自定义的 WCF 绑定,因为那些人​​决定使用“ISO-8859-1”作为他们的文本编码(而不是像网络上其他人一样使用 UTF-8),并且其他设置也很混乱 - 当然,没有记录在任何地方......

它已经工作了一段时间了,但突然间,我们的一些数据返回被破坏了。我们希望得到地名,并且在瑞士,其中一些地名带有德语变音符号。但在过去的两三个月里,我们突然回来了,

Hünibach

而不是正确的

Hünibach

所以 ü(u 元音变音)被破坏了。

没问题,我认为他们最终切换到了 UTF-8,并且我更改了自定义绑定以使用 UTF-8 作为其文本编码器而不是 ISO-8859-1 - 但运气不佳 - 不,我得到:

异常:System.ServiceModel.Security.MessageSecurityException
客户端身份验证方案“Basic”禁止 HTTP 请求。

什么啊?????该服务受到我们使用 WCF 的 ClientCredentials 传入的用户名/密码的保护。似乎更改文本编码会以某种方式弄乱凭证!?!?!奇怪......

好吧 - 回到 ISO-8859-1,我只是尝试将响应有效负载解释为 UTF-8 - 再次没有运气:-( 甚至尝试过 UTF-16、UTF-32、UTF-7 、Unicode、BigEndianUnicode -

那么我究竟如何取回正确的变音符号,并且仍然能够调用该该死的服务......在 SoapUI 中工作得很好,顺便说一句......

有什么想法吗?我拼命抓住你可能扔给我的任何一根稻草!

I have a really weird WCF problem here...

We're connecting to a crappy third-party web service; it was a nightmare to even get it going, we had to create a custom WCF binding since those guys decided to use "ISO-8859-1" as their text encoding (instead of UTF-8 like everyone else on the web), and the other settings were messy, too - and not documented anywhere, of course...

It's been working ok for a while now, but suddenly, some of our data coming back in mangled up. We expect to get back names of places, and being in Switzerland, some of those have German umlauts in them. But for the past two or three months, we suddenly get back

Hünibach

instead of the proper

Hünibach

So the ü (u umlaut) is mangled.

No problem, I figured they finally switched to UTF-8, and I changed my custom binding to use UTF-8 as its text encoder instead of ISO-8859-1 - but no luck - no I'm getting:

EXCEPTION: System.ServiceModel.Security.MessageSecurityException
The HTTP request was forbidden with client authentication scheme 'Basic'.

What the f????? The service is protected by a username/password which we pass in using the ClientCredentials of WCF. Seems that changing the text encoding somehow messes up the credentials !?!?! Weird.....

OK - back to ISO-8859-1, and I just tried to interpret the response payload as UTF-8 - again no luck :-( Tried with UTF-16, UTF-32, UTF-7 even, Unicode, BigEndianUnicode - all to no avail.

So how on earth do I get back my proper umlauts, and still be able to call that bloody service... works just fine in SoapUI, btw.....

Any ideas?? I'm desperately grasping at any straws you might throw me!!

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

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

发布评论

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

评论(2

小糖芽 2024-10-30 23:42:43

尝试检查您返回的数据,看看他们使用什么数字代码来表示它。元音变音是 8859-1 中与其他字符共享代码的字符之一。

请参阅第二段 - http://en.wikipedia.org/wiki/%C3% 9C#排版

Try inspecting the data you are getting back and see what numeric codes they are using to represent it. Umlaut is one of those characters in 8859-1 that shares code with other characters.

See second para in - http://en.wikipedia.org/wiki/%C3%9C#Typography

帅气尐潴 2024-10-30 23:42:43

事实上,我终于明白问题出在哪里了。

由于某种原因,将示例 CustomTextEncoder(由 Microsoft 在 WCF 和 WF 示例中提供)更改为使用 UTF-8 而不是 ISO-8859-1 不起作用

另一方面,从自定义绑定中删除自定义文本编码器并仅使用 WCF 从一开始就提供的标准 TextMessageEncoder(默认情况下使用 UTF-8)确实有效< /强>。

别问我为什么……这只是我发现的事实……

Actually, I finally figured out what the trouble was.

For some reason, changing the sample CustomTextEncoder (provided by Microsoft in the WCF & WF samples) to use UTF-8 instead of ISO-8859-1 doesn't work.

On the other hand, ripping out the custom text encoder from my custom binding and just using the standard TextMessageEncoder that WCF provides from the get go (which uses UTF-8 by default) did work.

Don't ask me why.... that's just the facts I found.....

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