【问题标题】:web api XmlMediaTypeFormatter exceptionweb api XmlMediaTypeFormatter 异常
【发布时间】:2012-07-10 12:17:02
【问题描述】:

我想使用IoC / web api框架的依赖解析器进行解耦。

XmlFormatter 不能序列化接口,...好的。但是如果我不能返回 xml,IoC 和 DependencyResolver 的目的是什么?

我什至不能这样做: (我的 ApiController 中的方法)

public HttpResponseMessage Get()
        {
            IEnumerable<Project> projects = new List<IProject>() { new Project(), new Project() }.Select(p => p as Project);

            HttpResponseMessage response = Request.CreateResponse<IEnumerable<Project>>(HttpStatusCode.OK, projects);

            return response;
        }

我创建了一个 IProject 列表并将它们转换为“Project”。但是在创建响应时,我得到了这个:

配置的格式化程序 'System.Web.Http.Tracing.Tracers.XmlMediaTypeFormatterTracer' 不能 编写一个“WhereSelectListIterator`2”类型的对象。

那是一个 XmlMediaTypeFormatterTracer?我不想跟踪在序列化时引发错误。 (顺便说一句:我用自己的 XMLformatter 替换了标准的 XMLformatter。但是“XmlMediaTypeFormatterTracer”抛出了异常...... 信息:我在使用标准格式化程序时遇到同样的错误)

即使我实现了自己的 xmlformatter,为什么还要调用这个 XmlMediaTypeFormatterTracer?

【问题讨论】:

    标签: interface inversion-of-control asp.net-web-api xml-formatting


    【解决方案1】:

    我的问题解决了

    config.Formatters.XmlFormatter.UseXmlSerializer = false;

    【讨论】:

      【解决方案2】:

      您是否在应用程序中启用了跟踪?如果是,则跟踪逻辑将格式化程序包装到其包装跟踪器格式化程序中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-02
        • 1970-01-01
        • 2017-10-11
        • 1970-01-01
        • 1970-01-01
        • 2015-01-24
        • 2012-05-04
        • 2016-12-02
        相关资源
        最近更新 更多