Top 10 WCF Interview Questions

By | June 15, 2012

A must have list of WCF Interview Questions that are asked during an Interview on hot topics with detailed answers and examples. After preparing following questions, reader will feel more comfortable about many key concepts in Microsoft Windows Communication Foundation. Along with these top 10 WCF Interview Questions, another complete four parts list of Interview Questions or FAQs (Frequently Asked Questions) on WCF for beginners as well as professional developers covering almost all topics in WCF.

So, if you really interested to know all about Windows Communication Foundation in simpler way or preparing for a WCF Interview Question, following WCF Tutorial Series will be very helpful:

In order to validate your WCF skills, you may take this WCF Online Test

MCSD Online Practice Exam: 70-487
  • Complete 40 Questions Exam in 90 Minutes
  • Real-time practical Scenario based questions.
  • Tests and improves one’s skill on Microsoft Azure, WCF Services, Web API, Web Services etc.
  • Goto Exam-70-487

WCF Interview Questions List

  1. What is the difference between WCF and ASMX Web Services?
  2. What are WCF Service Endpoints? Explain.
  3. What are the possible ways of hosting a WCF service? Explain.
  4. How we can achieve Operation Overloading while exposing WCF Services?
  5. What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly.
  6. What is DataContractSerializer and How its different from XmlSerializer?
  7. What are Contracts in WCF?
  8. Which standard binding could be used for a service that was designed to replace an existing ASMX web service?
  9. Please explain briefly different Instance Modes in WCF?
  10. Please explain different modes of security in WCF? Or Explain the difference between Transport and Message Level Security.

More WCF Interview Questions

1. What is the difference between WCF and ASMX Web Services?

Simple and basic difference is that ASMX or ASP.NET web service is designed to send and receive messages using SOAP over HTTP only. While WCF can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).ASMX Web Services Vs WCF

You can follow another tutorial WCF Vs ASMX for detailed discussion on this topic.
Back to Top

2. What are WCF Service Endpoints? Explain.

For Windows Communication Foundation services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role. Client uses endpoint to communicate with WCF Service. A WCF service endpoint has three basic elements i.e. Address, Binding and Contract.ABC's of WCF EndPoint

  • Address: It defines “WHERE”. Address is the URL that identifies the location of the service.
  • Binding: It defines “HOW”. Binding defines how the service can be accessed.
  • Contract: It defines “WHAT”. Contract identifies what is exposed by the service.WCF Endpoint

A WCF Service can have multiple endpoints configured to accommodate different clients, for example, one client may be using HTTP while other configured to communicate over TCP.

Back to Top

3. What are the possible ways of hosting a WCF service? Explain.

For a Windows Communication Foundation service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:

  • Hosting in a Managed Application/ Self Hosting
    • Console Application
    • Windows Application
    • Windows Service
  • Hosting on Web Server
    • IIS 6.0 (ASP.NET Application supports only HTTP)
    • Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP,
      NamedPipes, MSMQ.

If you are looking for implementation of all Hosting options, please follow here (Console | Windows Service | IIS | WAS)

Back to Top

4. How we can achieve Operation Overloading while exposing WCF Services?

By default, WSDL doesn’t support operation overloading. Overloading behavior can be achieved by using “Name” property of OperationContract attribute.

 [ServiceContract]
 interface IMyCalculator
 {
        [OperationContract(Name = “SumInt”)]
        int Sum(int arg1,int arg2);
        [OperationContract(Name = “SumDouble”)]
        double Sum(double arg1,double arg2);
  }

When the proxy will be generated for these operations, it will have 2 methods with different names i.e. SumInt and SumDouble.

Back to Top


Important Note: Remember that during a technical Interview, interviewer always ask about the latest feature of that particular technology, so be prepare for it also. For latest features series on Windows Communication Foundation v4.5, Click here.


5. What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly.

Windows Communication Foundation supports the following Message Exchange Patterns (MEPs):

  • Request/Response
  • One Way
  • Duplex

Request/Response
It’s the default pattern. In this pattern, a response message will always be generated to consumer when the operation is called, even with the void return type. In this scenario (void return type), response will have empty SOAP body.MEP Duplex (Request-Reply)
One Way
In some cases, we are interested to send a message to service in order to execute certain business functionality but not interested in receiving anything back. OneWay MEP will work in such scenarios. If we want queued message delivery, OneWay is the only available option. One-WayMEP
Duplex
The Duplex MEP is basically a two-way message channel. In some cases, we want to send a message to service to initiate some longer-running processing and require a notification back from service in order to confirm that the requested process has been completed.Duplex Request Reply

Duplex One Way

Please follow for detailed implementation for Message Exchange Patterns in WCF here.

Back to Top

6. What is DataContractSerializer and How its different from XmlSerializer?

Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we are talking about web services, serialization is very important.DataContractSerializer Vs XmlSerializer

Windows Communication Foundation has DataContractSerializer that is new in .NET 3.0 and uses opt-in approach as compared to XmlSerializer that uses opt-out. Opt-in means specify whatever we want to serialize while Opt-out means you don’t have to specify each and every property to serialize, specify only those you don’t want to serialize.
DataContractSerializer is about 10% faster than XmlSerializer but it has almost no control over how the object will be serialized. If we wanted to have more control over how object should be serialized that XmlSerializer is a better choice.

Programmers/Developers can enhance their programming skills by taking these 100+ Free Online Programming Courses.

Back to Top

7. What are Contracts in WCF?

A Contract is basically an agreement between the two parties i.e. Service and Client. In WCF, Contracts can be categorized as behavioral or structural.

  1. Behavioral Contractsdefinethatwhatoperationsclientcanperform on a service.
    • ServiceContract attribute is used to mark a type as Service contract that contains operations.
    • OperationContract attributes is used to mark the operations that will be exposed.
    • Fault Contract defines what errors are raised by the service being exposed.
  2. Structural Contracts
    • DataContract  attribute define types that will be moved between the parties.
    • MessageContract attribute define the structure of SOAP message.

Back to Top

8. Which standard binding could be used for a service that was designed to replace an existing ASMX web service?

The basicHttpBinding standard binding is designed to expose a service as if it is an ASMX/ASP.NET web service. This will enable us to support existing clients as applications are upgrade to WCF.

Back to Top

9. Please explain briefly different Instance Modes in WCF?

WCF will bind an incoming message request to a particular service instance, so the available modes are:

  • Per Call: instance created for each call, most efficient in term of memory but need to maintain session.
  • Per Session: Instance created for a complete session of a user. Session is maintained.
  • Single: Only one instance created for all clients/users and shared among all.Least efficient in terms of memory.PerCall - WCF

Please follow “3 techniques for Instance Management in WCF“.

Back to Top

10. Please explain different modes of security in WCF? Or Explain the difference between Transport and Message Level Security.

In Windows Communication Foundation, we can configure to use security at different levels

a.    Transport Level security means providing security at the transport layer itself. When dealing with security at Transport level, we are concerned about integrity, privacy and authentication of message as it travels along the physical wire. It depends on the binding being used that how WCF makes it secure because most of the bindings have built-in security.

  <netTcpBinding>
         <binding name=”netTcpTransportBinding”>
                    <security mode=”Transport”>
                          <Transport clientCredentialType=”Windows” />
                    </security>
          </binding>
  </netTcpBinding>

b.    Message Level Security
For Tranport level security, we actually ensure the transport that is being used should be secured but in message level security, we actually secure the message. We encrypt the message before transporting it.

   <wsHttpBinding>
            <binding name=”wsHttpMessageBinding”>
                          <security mode=”Message”>
                                     <Message clientCredentialType=”UserName” />
                          </security>
             </binding>
     </wsHttpBinding>

It totally depends upon the requirements but we can use a mixed security mode also as follows:

      <basicHttpBinding>
             <binding name=”basicHttp”>
                          <security mode=”TransportWithMessageCredential”>
                               <Transport />
                               <Message clientCredentialType=”UserName” />
                          </security>
              </binding>
       </basicHttpBinding>

Back to Top

More WCF Interview Questions for Experienced

How can we use ServiceMetadataContractBehavior class in WCF?

ServiceMetadataContractBehavior is a class that facilitates us to specify whether endpoint should be exposed in service metadata or not. As we already know that a WCF Service can have multiple endpoints, so in certain scenarios we might not be interested to publish metadata for a specific endpoint of our WCF service.ServiceMetadataContractBehavior

Back to Top

How we can use MessageContract partially with DataContract for a service operation in WCF?

MessageContract must be used all or none. If we are using MessageContract into an operation signature, then we must use MessageContract as the only parameter type and as the return type of the operation.MessageContract And DataContract

Back to Top

WCF Developer Jobs


Note: In this WCF Tutorial, we discussed about the most important top 10 interview questions and answers only but you can go through a series of questions on WCF Interview Questions here.

To test and further enhance your WCF skillsWCF Online Test

 

Top 10 Interview Questions and Answers Series:

Category: Interview Questions Tags: , ,

About IMRAN ABDUL GHANI

Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net, www.topwcftutorials.net, and www.sharepointfordummies.net.

21 thoughts on “Top 10 WCF Interview Questions

  1. Karthik

    Imran..you done a very good explaination about WCF questions…Keep it up..Post more questions on this.

  2. Anonymous

    Hey Imran, you are doing absolutely great job, It helps us a lot !!!!.

  3. Anonymous

    Thanks a lot Imran ..Really these are the top 10 question !!!!!!!!!!!!

  4. Anonymous

    Thanks Imran nice basic understaning for WCF (Moez)

  5. Top 10 Interview Tips

    I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

  6. Anonymous

    I think “single ” instance mode should be most efficient in terms of memory. There is only one object being created

    1. imranghani

      Dear, single is least efficient in terms of memory. Although its a single instance but it lives in memory almost forever and disposed off only when host process gets down.

Comments are closed.