WCF, containers in DataContract
I need to pass som开发者_JAVA百科e container of objects to WCF call
[DataContract]
class Foo
{
// other fields omited
[DataMember]
public List<Foo> MyList;
}
Is it OK for serialization? If not what are my options?
It's ok but the resulting type will be an array and not a list. I'm partial to using array in the contract just to make sure I don't try to use it as list someplace else.
It will successfuly serialize even if you don't apply DataContract. The only condition is that all used types in serialization have parameterless constructor (even private will do), e.g:
List<T> - already has it.
Foo - have it by default.
精彩评论