I have a very simple custom collection type that inherits from List <> and uses CollectionDataContract.
When I use DataContractSerializer.WriteObject to serialize it, it respects the CollectionDataContract attribute as I expected; however, when I use it as the return type for the WCF method, I get the default ArrayOfFoo.
I am wondering if there is any decoration that I am missing in the service contract.
More details:
[DataContract(Namespace = "")]
public class Foo
{
[DataMember]
public string BarString { get; set; }
}
[CollectionDataContract(Namespace = "")]
[Serializable]
public class FooList : List<Foo> {}
If I just create an instance of Foo and then use DataContractSerializer.WriteObject to serialize it, I get what you expect:
<FooList>
<Foo>
<BarString>myString1</BarString>
</Foo>
</FooList>
However, if I have a service with this method ...
[ServiceContract Name = "MyService"]
public interface IMyService
{
[OperationContract, WebGet(UriTemplate = "foos/")]
FooList GetAllFoos();
}
GET http://www.someEndpoint.com/foos/, :
<ArrayOfFoo>
<Foo>
<BarString>myString1</BarString>
</Foo>
</ArrayOfFoo>
Name= "MyFooListName" CollectionDataContract. : DataContractSerializer ; WCF .