Saturday, February 19, 2011
WCF Interview Questions on Contracts - Part 3
Click here for all SQL Server Interview Questions
Click here for all WCF Interview Questions
Click here for all ASP.NET Interview Questions
Click here for all C# Interview Questions
Click here for Written Test or practical ASP.NET Interview Questions asked in MNC's
What is the best way to serialize Polymorphic Types in WCF?
The best way to serialize Polymorphic Types in WCF is to use KnownType attribute on the parent type as shown in the example below. CorporateCustomer and PremiumCustomer classes inherit from Customer class, and hence we can associate CorporateCustomer and PremiumCustomer types as known types in 3 different ways depending on the project requirement.
1. Associate known types to the base types themselves.
2. Associate known types to particular operations.
3. Associate known types to the service contract as a whole.
In Example 1, we are associating known types, CorporateCustomer and PremiumCustomer to the base type, Customer.
In Example 2, we are associating known type, CorporateCustomer on SaveCorporateCustomer(Customer customer) and GetCorporateCustomer(int CustomerId) operations using ServiceKnownType attribute.
In Example 3, we are associating known types, CorporateCustomer and PremiumCustomer to the service contract ICustomerService as a whole.
It is also possible to specify known types in a configuration file rather than in code. Example 4 shows how to specify known types in configuration.file.
Click here for all SQL Server Interview Questions
Click here for all WCF Interview Questions
Click here for all ASP.NET Interview Questions
Click here for all C# Interview Questions
Click here for Written Test or practical ASP.NET Interview Questions asked in MNC's
Subscribe to:
Post Comments (Atom)
Best compilation of questions and answers...Thank You...
ReplyDeleteRocking explanation tons of likes
ReplyDeleteHere are the questions I was asked in an interview
ReplyDeleteWhat is Message Contract?(I see this already explained in this blog on some other page)
Is method overloading possible in WCF?
What are the different modes in WCF?
What is fault contract in WCF?
Difference between IIS 6 and IIS 7 when it comes to WCF hosting ?
Method overloading possible in WCF By adding Name attribute in Operation contract.
Delete