Search code examples
c#azureservicebusazure-worker-rolesbrokeredmessage

BrokeredMessage Deseralization comes with unwanted String


Passing a brokered message over ServiceBus with out any custom DataContractSerializer[as Default XML Serializer Take Place].

var message = new BrokeredMessage(objMess.MessageBody);

Note: Mainly the message body is type of HTML Emails.

But When on the message delivered to worker role after deserialization , i see some random text is appended in top body,

var reader = new StreamReader(receivedMessage.GetBody<Stream>());

@string3http://schemas.microsoft.com/2003/10/Serialization/�  .
Rest of Message Body 

i tried to give custom DataContractSerializer. but that messed up with HTML symbols.

Some Formatting the content for Service Bus messages article i found but still finding a way to get rid of schema String.

As per now i doing substring with message body.


Solution

  • Seems like you have mismatched sender and receiver types. ServiceBus BrokeredMessages should be used like this:

    1) If you send with var message = new BrokeredMessage(object) you should receive with receivedMessage.GetBody<typeof(object)>()

    2) If you send with var message = new BrokeredMessage(object, XmlObjectSerializer> -> you should receive with receivedMessage.GetBody<typeof(object)>(XmlObjectSerializer)

    3) If you send with var message = new BrokeredMessage(Stream) You should receive with receivedMessage.GetBody<Stream>

    This should be transparent to you. Just put the type that you are sending in the Receiver. receivedMessage.GetBody<String>() if it's a string or receivedMessage.GetBody<TypeOfMessageBody>()