DataContractSerializer’s ServiceKnownType & KnownType attributes

February 17, 2009

When we use WCF in conjunction with DataContractSerializer one notices that there are 2 attributes you can use: ServiceKnownTypeAttribute and KnownTypeAttribute KnownTypeAttribute: Let’s say you have the following classes: 1. Person 2. Employee – derives from Person If you mark each class with the DataContract attribute and create a service operation that returns a Person type, you will be able to return a Person, but not an Employee. If you try to return the latter, you’ll receive either a serialization error...