0

I am sending a message from a C# worker to the Queue, then I am getting it on another C# worker and call

string body = message.GetBody<string>();

This works and I later de-serialize the string/JSON message.

Now I am trying to send the same message from NodeJS in form of a JSON message. When I try to receive it and

string body = message.GetBody<string>();

call this I get an exception saying the input is in incorrect format.

My message object on NodeJS looks like this

{
  body: JSON.stringify(message)
}

Any ideas?

Daniel Wardin
  • 1,840
  • 26
  • 48

1 Answers1

5

Got it fixed!

By default the .NET Azure Queue library uses a DataContractSerializer and a binary XmlDictionaryWriter to serialize the string message when using

new BrokeredMessage("my message");

So instead you need to use this

new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes("my message")), true);

and to read the message in C# you need to use

string body = new StreamReader(message.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();

I also stopped wrapping my JSON.stringify message in an object and pass it directly to the sendQueueMessage. The send message code looks like this now:

serviceBusService.sendQueueMessage('my_queue', JSON.stringify("my message"), function(error){});

JSON.stringify outputs a UTF8 string so it is fully compatible with the C# code.

Daniel Wardin
  • 1,840
  • 26
  • 48