WEB API to return object following serialization attributes

前端 未结 1 1820
渐次进展
渐次进展 2021-01-25 23:19

I am using WEB API to return an object (class).

Class is already being structured using System.Xml.Serialization attributes, which makes if difficult to return entire cl

相关标签:
1条回答
  • 2021-01-25 23:45

    ASP.NET Web API does use the serialization attributes defined at the class level. However, XmlMediaTypeFormatter uses DataContractSerializer by default. Since you are using XmlSerializer, you need to tell Web API to use the same, like this.

    GlobalConfiguration.Configuration.Formatters
                          .XmlFormatter.UseXmlSerializer = true;
    
    0 讨论(0)
提交回复
热议问题