【问题标题】:WCF, xml creates ExtensionData tag which I want to removeWCF,xml 创建我要删除的 ExtensionData 标记
【发布时间】:2013-11-20 22:36:55
【问题描述】:

我从 WCF 项目创建了一个“列表”,并且正在测试项目中使用该服务。在 javascript 中使用 XMLSerializer,我能够创建 XML 结果。但是这个“ExtensionData”标签很烦人。

例如,

<?xml version="1.0"?>
<ArrayOfStudent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Student>
    <ExtensionData/>
    <Name>Chris</Name>
    <Age>72</Age>
</Student>
<Student>
    <ExtensionData/>
    <Name>Christine</Name>
    <Age>2400</Age>
</Student>

我尝试添加

[ServiceBehaviorAttribute(IgnoreExtensionDataObject = true)]
public class StudentService: IStudentService
{
}

但是,没有运气..

【问题讨论】:

    标签: c# javascript wcf xmlserializer datacontractserializer


    【解决方案1】:

    您是否尝试为 List 创建一个新类并使用 [CollectionDataContractAttribute],因为在您的情况下,.Net 为 List 创建了一个新类型并将其命名为 ArrayOfStudent。

    这可能会解决您的问题。

    public StudentList ListStudents()
    {
        // return new List<student>();
           return new StudentList(); 
    }
    
    [CollectionDataContract()]
    public class StudentList : List<Student>
    {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-12
      • 2011-08-22
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      相关资源
      最近更新 更多