0
在ASP.NET Web API中,我需要強制XML輸出用於單個方法,但保留爲其他用戶啓用JSON格式化程序。我看到的題目一切都建議從GlobalConfiguration取出JSON格式如下:在ASP.NET Web API中選擇性地禁用XML格式化程序
// remove JSON formatter
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.JsonFormatter);
這工作,但廣泛禁止JSON輸出應用。我需要能夠指定特定方法或控制器的格式化程序而不影響全局配置。這是可能的還是隻能通過GlobalConfiguration完成?
這工作完美,除了我需要使用System.Net.Http.Formatting.XmlMediaTypeFormatter而不是XMLFormatter。 – rybl