【发布时间】:2015-06-10 12:37:23
【问题描述】:
如何让 HttpResponseMessage 遵循 xml 架构而不是数据契约?
我试过了
return new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new ObjectContent<Foo>(foo, Configuration.Formatters.XmlFormatter)
};
但这并没有奏效。
另外,如果我这样做,Action 将始终为 xml 提供服务,并且不会进行内容协商。我尝试将 List 添加为参数,但 HttpResponseMessage 不期望一个列表,只是一个项目。
有没有办法在不使用 DataContract 的情况下进行内容协商?基本上现在 HttpResponseMessage 正在忽略 xml 架构。
【问题讨论】:
标签: asp.net-web-api content-negotiation