Search code examples
c#azurebiztalkappfabricservicebus

Message.GetBody(); Serialization Loop


I have a problem with serializing a message from Windows Azure ServiceBus.

When i Call the "message.GetBody();" method it ends up in some kind of loop which makes my azure-emulator allocate all memory available on the machine.

My code:

            Microsoft.ServiceBus.Messaging.BrokeredMessage message;
            while (true)
            {
                // SB is an instance of a class which let me receive a BrokeredMessage through its ReceiveMessage method.
                message = SB.ReceiveMessage("orders");
                if (message == null)
                {
                    break;
                }


                // This ends up allocating lots of memory until the debugger crashes.
                Procurement.TestOrder torder = message.GetBody<Procurement.TestOrder>();
            }

The Used Class:

[MessageContract(IsWrapped=false)]
public class TestOrder
{
    [MessageBodyMember]
    public int companyId { get; set; }
}

I have also tried using the [DataContract] and [DataMember] attributes on the TestOrder-Class.

By the way, the message is a pretty simple XML-File without any namespaces coming from BizTalk into a queue in azure.

There might be some small flaws with this but i dont see any reason for the serializer to get stuck in a loop.

Thanks in advance!


Solution

  • What error do you receive when using [DataContract] and [DataMember] to attempt to deserialize? If you just do Stream s = message.GetBody<Stream>(); what does s contain?

    If the payload of the string is text/XML as opposed to binary serialized XML you'll probably need to pass in a DataContractSerializer like this:

    torder = message.GetBody<TestOrder>(new DataContractSerializer(typeof(TestOrder)));