如何从azure服务总线队列中读取xml文件数据

时间:2017-06-08 12:10:10

标签: azure azureservicebus azure-servicebus-queues

我只想读取我从队列中发送到azure服务总线的XML文件数据。我的代码是

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

1 个答案:

答案 0 :(得分:2)

GetBody<T>尝试使用T将邮件反序列化为DataContractSerializer类型。

您可能想要的只是阅读string然后解析为XML:

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