What is WCF KnownType?
This article mainly explains "What is WCF KnownType". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's make up a small series to take you to learn "WCF KnownType is what"!
Notice the ClassWillProcessl type, what types do we need to add to KnownType? If we can assign instances of ClassB to ca in our application, we need to add ClassB to KnowType ([KnowType(typeof(ClassB))]), because ClassB derives from ClassA, so there is a downward cast in deserialization. If that is not possible, then leave it alone.
Since the declaration type of ia is an interface, we need to add the implementation class of the interface to WCF KnownType. Here are ImplA and ImplB. Imagine if we only added ImplA to KnownType and we assigned an instance of ImplB to ia, the deserialization engine would still deserialize it to ImplA because it only knows ImplA. If we put ClassC and ClassD in arraylist1 collection, since non-generic collections use Object to hold actual objects, we also need to add ClassC and ClassD to WCF KnownType. If we also want to store an array of int in numberValue (which rarely happens in practice), we also need to add int[] to WCF KnownType.
The ClassWillProcessl type with KnownType added is as follows:
[DataContract] [KnowType(typeof(ClassB))] [KnowType(typeof(ImplA))] [KnowType(typeof(ImplB))] [KnowType(typeof(ClassC))] [KnowType(typeof(ClassD))] [KnowType(typeof(int[]))] Public class ClassWillProcess { [DataMember] ClassA ca; [DataMember] InterfaceA ia; [DataMember] ArrayList arraylist1; Object numberValue; [DataMember] Public object Numbers { get {return numberValue;} set {numberValue=value;} } } At this point, I believe that everyone has a deeper understanding of "WCF KnownType is what", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!