Books MVC ASP.NET C# SQL Server WCF Written Test HR Round Subscribe C# Videos C# Programs Buy DVD

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

4 comments:

  1. Best compilation of questions and answers...Thank You...

    ReplyDelete
  2. Rocking explanation tons of likes

    ReplyDelete
  3. Here are the questions I was asked in an interview
    What 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 ?

    ReplyDelete
    Replies
    1. Method overloading possible in WCF By adding Name attribute in Operation contract.

      Delete

If you are aware of any other WCF questions asked in an interview, please post them below. If you find anything missing or wrong, please feel free to correct by submitting the form below.

 
Disclaimer - Terms of use - Contact Us