Pages

Men

rh

6/16/2012

What is Known Types in WCF

The Known Attributes enables you to design acceptable derived classes for a given Data Contract.It can be used in the following example.

Example:
[Datacontract()]
[KnownType(typeof(LoanApprovalTask))]
Class task
{
......
}

[Datacontract()]
Class LoanApprovalTask : Task
{
.....
}
When working with polymorphic types in your Service Contract, the KnownTypeAttribute is required because polymorphism is outside the paradigm of Service orientation. For example  you have following Service Contract.

[ServiceContract()]
 Interface ITaskManager
{
   [OperationContract()]
   List<Task> GetTaskByAssignmentName(String name)
}

if some of the objects  being returned by the GetTasksByAssignedName operation are LoanApprovalTask objects, the client can know how to deserialize these more specific tasks only if the KnowntypeAttributes was used.

No comments :

Post a Comment