known-types

How do you configure WCF known types programmatically?

落爺英雄遲暮 提交于 2019-11-26 18:27:47
My client/server application is using WCF for communication, which has been great. However one shortcoming of the current architecture is that I must use known type configuration for certain transmitted types. I'm using an in-house Pub/Sub mechanism and this requirement is unavoidable. The problem is that it's easy to forget to add the known type, and if you do, WCF fails silently with few clues as to what's going wrong. In my application, I know the set of types that are going to be sent. I would like to perform the configuration programmatically, rather than declaratively through the App

When is it appropriate to use the KnownType attribute?

筅森魡賤 提交于 2019-11-26 17:43:28
问题 After reading the MSDN reference, I still have questions about when to use the KnownType attribute. I understand that the attribute communicates type information to the serializer, but when is this needed? Is it appropriate when the class being serialized has references of a base class type, and there are up-cast derivative classes that could be set to those references? Moreover, are there any drawbacks to overusing the attribute? For instance, in the previous example, if the serialized class