c# - 更改MsmqIntegrationBinding的消息编码

标签 c# .net wcf msmq msmqintegrationbinding

我正在尝试使用带有 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/

相关文章:

带流的 WCF block 数据

c# - 如何判断一个Type是不是RunTimeType?

javascript - 在 JavaScript 中加密不会在 C# 中解密

c# - 是否可以直接打开Outlook session 窗口?

c# - 在 C# 中将 HTTP Accept 和 Content-Type header 都设置为 "application/xml"

c# - 如何创建包含 CRL 分发点的自签名证书

c# - Visual Studio 安装项目是否在卸载时保留了注册表项?

c# - BeginProcessRequest() 中发生了什么?

.net - 在 IIS 上发布 .NET6 C# Web 应用程序期间连接数据库时出错

.net - Adobe Air和.NET