[英]How to return a big XML response in C# Web API
I am creating a web api which need to create large XML responses according to various requests. 我正在创建一个Web API,该API需要根据各种请求创建大型XML响应。 I tried googling but all the answers are about XMLSerializer.
我尝试使用谷歌搜索,但所有答案都与XMLSerializer有关。
And I tried making XDocument object and returning it using toString() method. 我尝试制作XDocument对象,并使用toString()方法将其返回。 But it's not working properly too.
但是它也不能正常工作。 It gives me output like this
它给我这样的输出
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><root> <someNode>someValue</someNode> </root></string>
Isn't there an easy way to generate XML dynamically and return it. 没有一种简单的方法可以动态生成XML并将其返回。
Instead of generating XML dynamically, Why don't to use collection of class. 为什么不使用类的集合而不是动态生成XML? Make a generic class and assign the data in collection.
创建一个通用类并分配集合中的数据。 Send the collection using media header as xml.
使用媒体标头作为xml发送集合。
request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.