First of all, you need to put the [DataContract]
on every class that you want to have serialized and deserialized by WCF - it is not automatically inherited!
[DataContract]
class Parent
{
.....
}
[DataContract]
class Child : Parent
{
.....
}
If you're dealing with collections of things, then you might need to check into the CollectionDataContract
:
[CollectionDataContract]
[KnownType(typeof(Parent))]
[KnownType(typeof(Child))]
public class CustomCollection : List<Parent>
{
}
Also, WCF and SOA in general are quite a bit different from OOP and don't handle inheritance all that well. You will most likely have to put [ServiceKnownTypes]
or [KnownType]
attributes on your service contracts in places where you want to use and support polymorphism.
So if you have a service method that accepts a Parent
, but should also be able to accept a Child
instance as well, then you need to decorate the method with the [KnownType]
attribute to make this information available to WCF.
See the MSDN Documentation on the KnownType attribute, or check out this other SO question on the topic.
Marc