Preparation technology:
1.c# Basic Knowledge
2. Learn about WCF Basics
In normal C # development We are allowed to replace the base class with subclasses, which is also known as the substitution principle. But we do not replace the parent class with the subclass of the data contract in WCF because there is a problem with serialization. As an example:
We have data contracts:
[DataContract]
Class employee{...}
In the service contract:
[ServiceContract]
Interface Iemployeemanager
{
[operationcontract]
void AddEmployee (employee employee);
}
Then we have a class in the proxy of the client: intern inherits from
[DataContract]
Class intern:employee{...}
And then when the client calls:
Proxy. AddEmployee (new Intern ()) is an error. Because the Intern object is not recognized on the server side because he cannot deserialize intern into an Employee object (WCF serialization).
WCF offers us a solution by using the KnownTypeAttribute feature to identify the corresponding subclass on the base class. The KnownTypeAttribute feature can be used on struct and class. Example:
[DataContract]
[Knowntype (typeof (Customer))]
Class employee{...}
[DataContract]
Class intern:employee{...}
So that we can cross all the services and endpoints on all contracts and operations, allowing the service to accept subclasses. But this will encounter a problem, we can not go to specify a certain service operation, so the Knowntype flaw is too wide. WCF provides another attribute--serviceknowntype.