简体   繁体   English

打印将从Web服务返回的XML

[英]Print XML that is going to be returned from web service

I have a .NET web service that returns an object and I get an XML response. 我有一个返回对象的.NET Web服务,并且得到了XML响应。 I am trying to debug because the response is receiving the correct XML on one machine, but not on another. 我正在尝试调试,因为响应是在一台计算机上接收到正确的XML,而不是另一台计算机上。

I would like to print the XML that is going to be returned from the web service right before the return statement on the web service side. 我想在Web服务端的return语句之前打印将要从Web服务返回的XML。 Is there any way to do this? 有什么办法吗?

[WebGet(UriTemplate = MY_URI_TEMPLATE)]
public MyReturnObject DoUpdate(string myParam)
{
    ...
    MyReturnObject retVal = new MyReturnObject(myParam)

    //I want to print the XML that is going to be returned for MyReturnObject here

    return retVal;
}

How about using the DataContractSerializer . 如何使用DataContractSerializer Something along these lines 这些东西

MyReturnObject retVal = new MyReturnObject(myParam)
var serializer = new DataContractSerializer(retVal.GetType());

using (var xmlData = new StringWriter())
using (var writer = XmlWriter.Create(xmlData))
{
    serializer.WriteObject(writer, retVal);
    Console.WriteLine(xmlData.ToString());
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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