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 2


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 are the different options available to serialize complex types that are sent and received between clients and services in WCF?
The following are the different options available to serialize complex types that are exchanged between clients and services in WCF. These options have their own advantages and disadvanatages. Data contracts is the preferred way to serialize complex types in WCF.
1. Serializable types - Us the Serializable attribute on the type that you want to serialize
2. Data contracts - Use DataContract attribute on the type and DataMember attribute on every member of the type, that you want to serialize. You can apply DataMember attribute either on a filed or a property.
3. Known types - Use Known types to enable polymorphic behavior in service contracts.
4. IXmlSerializable - IXmlSerializable types provide XSD schema to Web Services Description Language (WSDL) and metadata exchange (MEX).


What is the disadvantage of using Serializable attribute to serialize a complex type that is sent and received between clients and services in WCF?
When we decorate a class with Serializable attribute, all the fields of the class are serialized regardless of the accessibility. We donot have control on what to serialize and what not to serialize. We also will not have any control over naming conventions or data types.


What is the preferred way for serializing complex types in WCF?
The preferred way for serializing complex types in WCF is to use data contracts. Using Data Contracts provides us with the following advantages.
1. Using DataMember attribute, you can control which members of the class to serialize.
2. You can also control the order in which members are serialized using Order parameter of the DataMember attribute..
3. You can also provide explicit Name to the serialized members using Name parameter of the DataMember attribute.
4. You can also specify if a member is required or optional using IsRequired parameter of the DataMember attribute.


Consider the example below which uses Name, IsRequired and Order parameters of the DataMember attribute to serialize CustomerId property. By the way DataMember attribute can be used with either fields or properties. If you donot specify the order in which members are serialized, then by default alphabetical ordering is done by the DataContractSerializer.
   


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

9 comments:

  1. hey venkat can u pls make wcf video series for the viewers that would be gr8 ... if u think we r valuable for u .. pls

    ReplyDelete
    Replies
    1. Hi Bhabhesh

      Thank you very much for taking time to give feedback. You are definitley valuable to me. I will record and upload WCF videos as soon as I can.

      If you want to receive email alerts when new videos are uploaded, please feel free to subscribe to my youtube channel. at the following link.
      http://youtube.com/kudvenkat

      Dot Net Basics, ASP.NET, C#, and SQL Server video tutorial play lists can be found at the following link. All the videos are arranged in a logical sequence in these playlists.
      ASP.NET, C# and SQL Server Video Tutorial

      Delete
  2. when we can expect the wcf video tutorial from u.

    ReplyDelete
  3. when we can expect the wcf video tutorial from u.
    Plz upload video tutorial .

    ReplyDelete
  4. hey venkat can u pls make wcf video series for the viewers that would be gr8

    ReplyDelete
    Replies
    1. Hi, sure, I will record and upload WCF videos as soon as I can.

      Delete
  5. how to access service by only post

    ReplyDelete
  6. In Recent Interview ,I was asked the question on throttling? How its calculated ?which context modes can be used?Can we use PerSession Context Mode with throttling enable?

    ReplyDelete

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