Just to explain the answer to Andrey and share my experience, I just went through a problem that I finally solved with CollectionDataContract. In principle, to interact with a specific system, I wanted to be able to send and receive xml format:
<SomeMessageList> <Message> <ID>blah</ID> <data1>blah</data1> <data2>etc.etc.</data2> </Message> <Message> <ID>blah</ID> <data1>blah</data1> <data2>etc.etc.</data2> </Message> //any number of repeated <Message> here </SomeMessageList>
However, if I used an array or List object, the root tag was always called ArrayOfMessage. And if I created a class that contained an array of Message objects (for example, called MsgList), then WCF will add this as an additional tag to the mix that I could not find to get rid of it. So it would look like this:
<SomeMessageList> <MsgList> <Message> <ID>blah</ID> <data1>blah</data1> <data2>etc.etc.</data2> </Message> //any number of repeated <Message> here </MsgList> </SomeMessageList>
So CollectionDataContract just gave me an easy way to control the name of the root list item.
source share