Webapi 2没有给出XML格式的列表 [英] Webapi 2 not give list in XML
本文介绍了Webapi 2没有给出XML格式的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public IEnumerable<Word> GetWords()
{
return db.Words.ToList();
}
我需要使用webapi2以XML格式输出这个输出;
我尝试了什么:
i已经google并尝试
I need this output in XML using webapi2;
What I have tried:
i already google and try
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "text/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
它仅以JSON格式提供数据。
我也更新以下包:
Microsoft.AspNetCore.Mvc.Formatters.Xml
但怎么能我用XML格式了。
提前谢谢。
It gives data only in JSON.
also I update following package:
Microsoft.AspNetCore.Mvc.Formatters.Xml
But how can I get it in XML.
Thanks in advance.
推荐答案
你可以使用
Configuration.Formatters.XmlFormatter
public IHttpActionResult Get()
{
//Your code to get the result object
return Content(HttpStatusCode.OK, results, Configuration.Formatters.XmlFormatter);
}
这篇关于Webapi 2没有给出XML格式的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文