【发布时间】:2012-03-15 22:45:18
【问题描述】:
我非常喜欢 HttpClient 的架构方式 - 但我不知道如何添加“不太标准”的媒体类型以由 XmlSerializer 处理。
这段代码:
var cli = new HttpClient();
cli
.GetAsync("http://stackoverflow.com/feeds/tag?tagnames=delphi&sort=newest")
.ContinueWith(task =>
{
task.Result.Content.ReadAsAsync<Feed>();
});
当指向 Content-Type 为“text/xml”的原子提要时工作正常,但示例中的那个失败并显示 “No 'MediaTypeFormatter' is available to read an object of type 'Feed'带有媒体类型'application/atom+xml'" 消息。 我尝试了为 XmlMediaTypeFormatter 指定 MediaRangeMappings 的不同组合(作为参数传递给 ReadAsAsync),但没有成功。
配置 HttpClient 以将“application/atom+xml”和“application/rss+xml”映射到 XmlSerializer 的“推荐”方式是什么?
【问题讨论】:
标签: c# .net wcf wcf-web-api