Top 10 WCF Interview Questions and Answers

WCF Interview Questions and Answers 
1. What is WCF?

Windows Communication Foundation (WCF), earlier known by the name Indigo, is a run-time platform and a set of APIs in the .NET Framework for building, configuring, and deploying Service Oriented Applications. It was deprecated to develop advanced HTTP-based web services. It supports multiple languages and multiple platforms.

2. What are the fundamentals of WCF?

These are the fundamentals of WCF as follows:


A message is the communication unit in the form of an envelope for the transmission of the data from the client to Service and Service to the client and has two sections: Header, Body.


Endpoint describes the address of Web Service from where a user can receive and send the message by specifying the communication mechanism of how the message will be sent or received.

It consists of three things (A, B, and C) with question marks:

  • Address (Where?)
  • Binding (how?)
  • Contract (What?)

Endpoint = A + B+ C

Address locates the WCF Service, where the Service hosted? With the exact URL of Web Service as given-


Binding is the mechanism by which the user communicates with Web Service. It is the constitution of some elements that bind together and creates the structure of communication such as some transport protocols like HTTP, TCP, etc. including message format or security techniques also.

A contract is the interface name which has all the operation need to be exposed as it specifies what the Service is providing functionality and operation. It also determines what functionality and operation need to be exposed to the client.


Hosting makes WCF Application different from other distributed Applications. It consists of the following types:

  • IIS Hosting
  • Self-Hosting
  • WAS Hosting


SOAP (Simple Object Access Protocol) is an XML based message protocol and not a transport protocol.

3. Why we use WCF?

These are the following features of WCF as the reason for its use:

Service Orientation

WCF enables us to create service-oriented applications. The architecture of WCF is service-oriented that makes it a reliance on Web services to send and receive data. WCF services are loosely-coupled from one application to another, implies that any client from any endpoint can connect to any service as long as the essential contracts met.


WCF implements modern industry standards for Web service interoperability by providing a set of specifications known as web specifications and makes web services interoperable.

Multiple Message Patterns

There are several message patterns in which the messages exchanged as follows:

  1. The most common pattern is the request/reply patternin which one endpoint requests data from a second endpoint and get replied by the second endpoint in response.
  2. The second one is a one-way message pattern in which a single endpoint sends a message without any expectation of any response.
  • The third one is the more complex pattern known as the duplex exchange patternin which the two endpoints make a connection and send data back and forth manner similar to an instant messaging program.

Service Metadata

WCF supports service metadata (set of data about other data) to get published over HTTP and HTTPS by using formats specified in industry standards such as WSDL, XML Schema and WS-Policy, in use to generate and configure clients for accessing its services automatically.

Data Contracts

As WCF built by using .NET Framework, it includes code-friendly methods of supplying the contracts to enforce such as data contract, one of the universal types of contract. If you code your Service using Visual C# or Visual Basic, you will get the easiest way to handle data by creating classes that represent a data entity with properties that belong to the data entity. You get a comprehensive system for working with data in this secure manner.

Your Service will automatically generate the metadata and allows clients to comply with the data types you have designed with the help of classes to represent data.


Messages encryption done for privacy concern, and you can require users to authenticate themselves before being allowed to receive messages. Security concern can implemented by using well-known standards such as SSL or WS-Secure Conversation.

Reliable and Queued Messages

WCF has reliable sessions implemented over WS-Reliable Messaging and MSMQ to support reliable message exchange.


WCF supports the transactions with the help of these three transaction models:

  1. WS-Atomic Ttransactions
  2. Transactions namespace
  • Microsoft Distributed Transaction Coordinator


WCF architecture has several extensible points such that if any user requires additional capability, it opens several entry points to customize the behavior of a service.

4. What are the differences between WCF and Web Services?

  • Web services get invoked by HTTP only.

Any protocol and any transport type can invoke WCF component or services.

  • Web Services are available in the namespace “System.Web.Services.WebService Class”.

 WCF is available in the namespace “System.ServiceModel”.

  • Web Services support only IIS hosting.

WCF supports hosting like IIS hosting, Self-hosting (Console Hosting), Windows Services, and Windows Activation Services.

  • Web Services support one-way communication and Request-Response.

WCF supports one-way, two-way communication, and Request-Response.

  • In case of Binding:

Web Services support XML 1.0, Message Transmission Optimization Mechanism (MTOM), Custom bindings.

WCF supports XML 1.0, Message Transmission Optimization Mechanism (MTOM), Binary and Custom bindings.

  • WCF is faster than Web Services.
  • Hash Table can be serialized using WCF.

Web Services doesn’t enable Hash Table serialization.

  • WCF supports multi-threading by using ServiceBehaviour

Web Services doesn’t support multi-threading.

5. What is WCF Service Binding?

WCF Service Binding is a set of numerous binding elements in which each of the element specifies the way of communication between Service and client in terms of transport protocols (like HTTP or TCP) and encoding (such as text or binary). The binding elements specify security mechanisms used to secure messages or the message pattern used by the Service and client.

6. What are the different types of bindings in WCF?

Basic Binding

It uses HTTP as the transport and text/XML as the default message encoding. Basic Binding offered by the BasicHttpBinding class and suitable for communicating with ASP.NET Web services (ASMX)-based services.

Web Service Binding

The WSHttpBinding class offers it. It uses protocols for transport as Basic Binding uses but also provides many WS-* specifications like WS-Reliable Messaging, WS-Transactions, WS-Security, etc.

IPC Binding

It uses Named pipe protocol and given by the netNamedPipeBinding class. It is the fastest Binding and the most secured amidst all the existed bindings. It fully supports SOAP security, transaction, and reliability.

TCP Binding

It uses TCP protocol to communicate within the same network and encodes the message in binary format. The NetTcpBinding class offers this type of Binding. It gives a secure and reliable binding environment for .Net to .Net cross-machine communication.

Peer Network Binding

It makes use of peer networking as transport alongside TCP protocol. The NetPeerTCPBinding class provides it. This type of Binding is used in file sharing systems like a torrent. It fully supports SOAP security, transaction, and reliability.

MSMQ (Microsoft Message Queuing) Binding

It uses MSMQ for transportation and support detached message queuing. NetMsmqBinding class offered MSMQ Binding and is used to provide secure and reliable queued communication for the cross-machine environment.

MSMQ integration binding

The MsmqIntegrationBinding class offers it. It enables communication with existing systems which communicate through MSMQ.

7. What is the functionality of the Message layer in WCF?

Message layer consists of channels and specifies what formats and data exchange patterns can be used when communicating with the services. These channels process messages and operate on messages and message headers. The Message layer has eight channels divided into two categories, as follows:

  1. Transport Channels helps to read and write messages from the network. Example:
  • WS Security Channel
  • WS Reliable Messaging Channel
  • Encoders like Text, Binary, XML, and MTOM.
  1. Protocol Channels are used to implement message processing protocols. Example:
  • HTTP Channel
  • TCP Channel
  • MSMQ
  • Named Pipe Channel
  • Transition Flow Channel

8. Describe the various ways of hosting a WCF service?

IIS (Internet Information Services) Hosting is the most commonly used hosting method.  Its best feature is that it automatically activates the services. IIS hosting enables health monitoring, idle shutdown, process recycling, and many other IIS features to facilitate a WCF service hosting. It supports only HTTP Protocol.

Self- Hosting enables developers to host a WCF service in a managed application. The developers have to write the necessary coding for ServiceHost initialization. And they can host a WCF service in any application like a console application, Windows Form, etc.

WAS (Windows Activation Service) Hosting is the most advantageous technique to host a WCF service as it is enriched with features such as process recycling, isolation, idle time management, common configuration system. It supports HTTP, TCP, Named pipe protocols for transportation.

Windows Service Hosting is best suitable for local system clients to host a WCF service. It is advantageous because of some features such as all the versions of Windows support it, the Service get hosted when the system starts, and Service Control Manager can control the process lifecycle of  WCF service.

9. List the protocols that WCF used in Message layer.

  1. Ws-Security Channel
  2. Ws-Reliable Messaging Channel
  3. Encodes
  4. HTTP Channel
  5. TCP Channel
  6. Transaction flow channel
  7. Named Pipe Channel
  8. MSMQ Channel

10. List the different WCF contracts.

These are the different WCF contracts as follows:

  1. Service Contracts define the operations that a client can perform on the Service. Example: ServiceContract, OperationContract.
  2. Data Contracts specify the data types which are passed to and from the Service. Example: DataContract, DataMember.
  3. Message Contracts enable service interaction directly with messages.
  4. Fault Contracts specify the way to handle the WCF error/exception.