使用 C# 将消息作为 ASCII 写入 MQ
Write Message to MQ as ASCII using C#
我有一个 XML 形式的字符串或与此相关的任何字符串,当它写入 MQ 时我得到了 BOM。我试图在 C# 应用程序中将字符串转换为 ASCII,但它仍然显示在 MQ 的消息中。
我以为我可以使用 MQMessage()
中的编码方法
MQQueueManager queueManager = new MQQueueManager();
queue = queueManager.AccessQueue(QueueName,
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = strInputMsg;
queueMessage = new MQMessage();
queueMessage.WriteString(message);
queueMessage.Format = MQC.MQFMT_STRING;
queueMessage.Encoding = MQC.MQENC_NATIVE;
queuePutMessageOptions = new MQPutMessageOptions();
queue.Put(queueMessage, queuePutMessageOptions);
我不确定 queueMessage.Encoding 行的值应该是多少。
另一个问题是编码为 ASCII 会去除位对象标记(BOM)吗?
如果你看这里:https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.ref.dev.doc/q111220_.htm
ReadString, ReadLine and WriteString methods convert between Unicode
and the character set of the message; see CharacterSet
和
The WriteString method converts from Unicode to the character set
encoded in CharacterSet. If CharacterSet is set to its default value,
MQC.MQCCSI_Q_MGR, which is 0, no conversion takes place and
CharacterSet is set to 1200. If you set CharacterSet to some other
value, WriteString converts from Unicode to the alternate value.
因此,实际上在您调用 WriteString 之前,您在 .NET 中有一个 unicode 字符串。 WriteString 方法将该 unicode 转换为 CharacterSet 属性 指示的 CCSID,它默认为 unicode 并为您提供字节顺序标记 (BOM) 的有趣的 2 字节前缀。如果您将其设置为例如850,然后它会根据需要从unicode转换为单字节ASCII输出。
我有一个 XML 形式的字符串或与此相关的任何字符串,当它写入 MQ 时我得到了 BOM。我试图在 C# 应用程序中将字符串转换为 ASCII,但它仍然显示在 MQ 的消息中。 我以为我可以使用 MQMessage()
中的编码方法MQQueueManager queueManager = new MQQueueManager();
queue = queueManager.AccessQueue(QueueName,
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = strInputMsg;
queueMessage = new MQMessage();
queueMessage.WriteString(message);
queueMessage.Format = MQC.MQFMT_STRING;
queueMessage.Encoding = MQC.MQENC_NATIVE;
queuePutMessageOptions = new MQPutMessageOptions();
queue.Put(queueMessage, queuePutMessageOptions);
我不确定 queueMessage.Encoding 行的值应该是多少。
另一个问题是编码为 ASCII 会去除位对象标记(BOM)吗?
如果你看这里:https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.ref.dev.doc/q111220_.htm
ReadString, ReadLine and WriteString methods convert between Unicode and the character set of the message; see CharacterSet
和
The WriteString method converts from Unicode to the character set encoded in CharacterSet. If CharacterSet is set to its default value, MQC.MQCCSI_Q_MGR, which is 0, no conversion takes place and CharacterSet is set to 1200. If you set CharacterSet to some other value, WriteString converts from Unicode to the alternate value.
因此,实际上在您调用 WriteString 之前,您在 .NET 中有一个 unicode 字符串。 WriteString 方法将该 unicode 转换为 CharacterSet 属性 指示的 CCSID,它默认为 unicode 并为您提供字节顺序标记 (BOM) 的有趣的 2 字节前缀。如果您将其设置为例如850,然后它会根据需要从unicode转换为单字节ASCII输出。