In this articles we will discuss about significance of ServiceKnownType and KnownType attribute in WCF.
Lets look at an example to understand this:
In the above example we see a a servicecontract which adds vehicle and takes vehicle as a parameter and looking at the datacontracts we have a class called Car inherited from Vehicle.
Now on referencing this service at client side we expect to see Car class generated at client’s proxy but NO client proxy will not be able to generate car class, Since Car is not part of contract DataContractSerializer fails to serialize.
To solve this problem decorate the method or contract with ServiceKnownType attribute as shown below:
Alternatively we can use KnownType attribute at class level as shown below: