Wednesday 21 May 2008

WCF CollectionDataContract and DataMember attributes

We often use the WCF CollectionDataContract on a data contract so that the latter is generated as a collection (and not as an array) in the WCF Service proxy.

One day, I tried to define a data member inside a CollectionDataContract. Strangely, the data member was not generated in my proxy. It seemed that was not possible with WCF 3.0 (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2413798&SiteID=1)

[CollectionDataContract(...)]
public class MyCollectionDataContract : List
{
...
[DataMember(..)]
public string MyDataMember
{
...
}
}

The MyDataMember was not generated in the MyCollectionDataContract in the proxy.

2 comments:

Unknown said...

A working solution is in my blog: http://borismod.blogspot.com/2009/04/wcf-collectiondatacontract-and.html

Unknown said...
This comment has been removed by a blog administrator.