简体   繁体   中英

Getting Body content from MSMQ

I try to get the content of an item in a MSMQ - Queue.

When I look at that Entry using QueueExplorer the body content is like

[{"$type":"MyProject.MyClass.MyMethod, Messages","CustomerDecision":0,"OrderReferenceoId":"4fdb6be2-bfde-42b0-93fd-47058a326a24"}]

When I try to read the content using the following code, the body just contains weird crap, mostly \\0\\0 etc.:

message.Formatter = new XmlMessageFormatter(); 
var reader = new StreamReader(message.BodyStream);
var msgBody = reader.ReadToEnd();

(message is of type System.Messaging.Message)

It was a Coding Issue. The result LOOKED like random rubbish, but just was a unicode characterset. The following solved the problem:

message.Formatter = new BinaryMessageFormatter();
var reader = new StreamReader(message.BodyStream, Encoding.Unicode);
var msgBody = reader.ReadToEnd();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM