Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF collection serialization, IList or List? Does it matter?

Is there a preferable collections object when serializing over WCF? I'm trying to decide between List or IList, and wondering if it makes a difference?

like image 512
patrick Avatar asked Aug 10 '11 19:08

patrick


1 Answers

Does not matter from serialization point of view. There is no IList or List on the wire. Both will result in the same XML.

From MSDN:

All list collections of the same type are considered to have the same data contract (unless they are customized using the CollectionDataContractAttribute attribute, as discussed later in this topic).Thus, for example, the following data contracts are equivalent.

[DataContract(Name = "PurchaseOrder")]
public class PurchaseOrder1
{
    [DataMember]
    public string customerName;
    [DataMember]
    public Collection<Item> items;
    [DataMember]
    public string[] comments;
}

[DataContract(Name = "PurchaseOrder")]
public class PurchaseOrder2
{
    [DataMember]
    public string customerName;
    [DataMember]
    public List<Item> items;
    [DataMember]
    public BindingList<string> comments;
}
like image 119
Dmitry Avatar answered Oct 20 '22 03:10

Dmitry