WCF KnownType Attributes(Part-7)

When a message is sent over network, using WCF, it is serialized. When this code is recieved, the WCF API parses the XML and tries to create C# objects.When client sends an derived instance of the class then how it knows which class is instantiated?

The KnownType attribute informs the WCF if it can receive the derived instance of the class.

There are 4 different ways to associate KnownType in WCF.

  • KnownType Attribute in Base type
    • This is global and all service and operation contract should respect known type.

  • Associate Service knowntype Attribute in service contract
    • The scope for this knownType is all operation contract within this service only

  • Associate Service Knowntype Attribute in Specific Operation Contract
    • The scope for KnownType would be only the operation contract that is associated with Service KnownType

  • Associate KnownType in Configuration file
    • This is similar to associating KnownType with Base type.The scope is global.

Define KnownType in app.config:

You can refer the other WCF tutorials for better understanding:
WCF Service with Multiple Conract
Modify WCF service
Data Contract and Data Member

© 2015, www.techkatak.com. All rights reserved.

One thought on “WCF KnownType Attributes(Part-7)

Comments are closed.