Ole Albers
Ole Albers

Reputation: 9295

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)

Upvotes: 0

Views: 2481

Answers (1)

Ole Albers
Ole Albers

Reputation: 9295

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();

Upvotes: 2

Related Questions