Shubham Mittal
Shubham Mittal

Reputation: 9

how to read xml file data from azure service bus queue

I just want to read XML file data that i have sent in azure service bus from queue. My code is

while (client.Peek() != null)
{
    BrokeredMessage orderOutMsg = client.Receive();

    if (orderOutMsg != null)
    {
        // Deserialize the message body to a pizza order.
        XDocument orderOut = orderOutMsg.GetBody<XDocument>();
        Console.WriteLine("Received order, {0} {1} ", orderOut.Root.Element("Customer").Element("Location_Code").Value, orderOut.Root.Element("Customer").Element("Phone_Number").Value);

        orderOutMsg.Complete();    
    }    
}

Upvotes: 0

Views: 1012

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

GetBody<T> tries to deserialize the message into type T using DataContractSerializer.

What you probably want is just to read a string and then parse into XML:

var body = orderOutMsg.GetBody<string>();
XDocument orderOut = XDocument.Parse(body);

Upvotes: 2

Related Questions