ASP.Net Web API XML序列化ArrayOf [英] ASP.Net Web API XML Serialization ArrayOf

查看:82
本文介绍了ASP.Net Web API XML序列化ArrayOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.Net Web API(WCF 4.0)方法返回 List< WorkItem> .

I am using ASP.Net Web API (WCF 4.0) method to return a List<WorkItem>.

这将以ArrayOf ...形式返回xml

This is returning an xml with ArrayOf... in the form

<ArrayOfworkitem xmlns="http://schemas.datacontract.org/2004/07/AgilePortalServices.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <workitem>
        <id>28</id>
        <title>Test</title>
    </workitem>
    <workitem>
        <id>27</id>
        <title>Test Bug</title>
    </workitem>
</ArrayOfworkitem>

但我希望它返回为

<workitems>
    <workitem>
        <id>28</id>
        <title>Test</title>
    </workitem>
    <workitem>
        <id>27</id>
        <title>Test Bug</title>
    </workitem>
</workitems>

我该怎么做?

推荐答案

这是由于使用WCF XML序列化程序而不是默认XmlSerializer的序列化程序.

This will be due to the serializer using the WCF XML serializer, instead of the default XmlSerializer.

您可以通过设置默认格式化程序来进行修改(如果愿意,可以将其替换为第三方).

You can modify this by stting the default formatters (and you can replace this with a 3rd party if you choose to).

var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
xml.UseXmlSerializer = true;

更多信息,请参见此Web-API概述

这篇关于ASP.Net Web API XML序列化ArrayOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆