简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM