我正在尝试使用带有 MsmqIntegrationbinding 的 WCF 在 MSMQ 上发布消息。发送有效,但是当我查看已发送到队列的消息时。编码不正确。
是否可以将消息编码更改为 UTF-16?我已经尝试使用自定义绑定(bind)来解决这个问题。这并没有解决我的问题。我粘贴了下面使用的自定义绑定(bind)。
<binding name="CustomMsmqIntegrationBinding">
<textMessageEncoding messageVersion="None" writeEncoding="utf-16" />
<msmqIntegration exactlyOnce="true">
<msmqTransportSecurity msmqAuthenticationMode="None" msmqProtectionLevel="None" />
</msmqIntegration>
</binding>
最佳答案
问题是,您是否有理由强制您严格使用 UTF-16?
您是否在 MSDN 论坛中看到过此链接:"How to make UTF-16 as default encoding for WCF Data Services." ?
作为一种可能的解决方案,它建议:
The client can send Accept-Charset: utf-16 header in the request and the server will respond using UTF-16.
被接受的帖子说:
[...] UTF-8 supports the exact same set of characters as UTF-16. So unless you have a client which can only consume UTF-16 and not UTF-8 there should be no reason to use UTF-16 over UTF-8. To the contrary in fact, UTF-16 payloads are almost 2 times larger than UTF-8.
关于c# - 更改MsmqIntegrationBinding的消息编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9871739/