using or not using the KnownType attribute between servers?

232 views Asked by At

I have a question about using WCF KnownType attribute between Server / client application,
As you know there is different ways transferring objects between server and client using wcf.

  1. using knowntype.
  2. using DataContractResolver.
  3. using POCO to transfer the data of a knownType object (best practice).

what is the best way for (3) to pass the data ? is it as a serialized (xml / json / bufferProtocol) string ? as a class by it self (then we get the knowntype again) ?

1

There are 1 answers

0
Nick Harrison On

I have generally used POCO objects using DataContractSerializer. Under this approach, the DTOs were stored in a separate assembly accessible to both ends of the WCF conversation.

I have needed to explicitly use KnownTypes only when there was inheritance involved in the DTOs. For instance if the service contract specified a base class, but I was actually returning a derived class, I would need to explicitly state the inheritance with KnownType configuration.

This has been rare in my usage and generally not needed.

Decorate your POCO objects with DataContract attributes. Decorate the properties with DataMember attributes and the framework will take care of the rest.