Search code examples
c#javascriptwcfxmlserializerdatacontractserializer

WCF, xml creates ExtensionData tag which I want to remove


I create a 'List' from WCF project, and I am consuming the service in test project. Using XMLSerializer in javascript, I am able to create XML result. However this 'ExtensionData' tag is very annoying.

For example,

<?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>

I tried adding

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

but, no luck..


Solution

  • Did you try to create a new class for List and use [CollectionDataContractAttribute], because in your case .Net creates a new Type for List and name it as ArrayOfStudent.

    This may solve your problem.

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