In this article, I have mentioned Linq interview questions and answers but now in this article, I have mentioned 10+ WCF interview questions and answer which can be useful for beginners and experienced developers.

wcf-interview-questions-and-answers

1. What is WCF?

WCF stands for Windows Communication Foundation.

It is used to create a distributed and interoperable Applications. WCF is an effective platform for developing service-oriented applications.

It allows developers to create secure, reliable, and high profile development solutions which can be integrated across platforms and interoperate with existing investments.

2. What are the features of WCF?

  • Highly configurable transports
  • Better options for serialization
  • Well-integrated with IIS
  • Easy for self-hosting
  • Very rich metadata
  • Complex model for publication
  • Rich data contracts

3. What are the advantages of using WCF?

  • A major advantage is that WCF allows a single consistent access to windows communication technologies for developers thereby enabling easier development of SOA applications.
  • WCF provides interoperability between services.
  • Small changes in the configuration file will match your requirements.
  • It is platform-independent.
  • It can be hosted via several means (IIS, WAS, Self-hosting)

4. What are the core security features that WCF addresses?

  • Confidentiality
  • Integrity
  • Authentication and Authorization

5. What are the components used in WCF?

The WCF service main components for creating and consuming the service are Address, Binding, and Contracts. It is also called as endpoints. These are explained below:

  • Address: The address of the service will define where to send the messages. It identifies the endpoint and defines where the service is located. An URL (Uniform Resource Locator) property defines the address of the service. It’s mainly divided into 4 parts:
    • Schema: This is the first part of the address. It is mainly "HTTP:" or "HTTPS:"
    • Machine: It can be a URL like "localhost." or website domain name "example.com"
    • Port: It is optional and tells which port it should hit, example: "4455"
    • Path: To locate the service files.
  • Binding: It will define the communication of the client to the service. The protocol that is being used for communication to the client. The different protocols can be used based on the requirement. The binding mainly consists of three things that are mentioned below:
    • Protocol: It is mainly used to define the binding like security or transaction.
    • Transport: It mainly defines the base protocol that is being used for communication like TCP, HTTP, MSMQ and named pipes, etc.
    • Encoding: It is used in which format data should be sent, text or binary.
  • Contracts: The contracts are being used to provide the types of operations and structure that are being allowed between the client and service on which they agreed on for the process of communication. It mainly takes care of the type of operations, message form, input parameters and data, and response of the message. It is of many types that are mentioned below:
    • Data Contract: It is used to define the type of variable that will be used for the WCF service. A data contract is used to serialize and de-serialize the data. It helps in defining the format of data that needs to be passed from the service. It maps the common language runtime type to an XML schema. It is also referred to as a versioning system to manage the data. To define data contract, use [DataContract] and [DataMember] attribute.
    • Service Contract: It is used to define the operations that are being exposed to others. It acts as an interface for the service. It defines the name and namespace for the service. It is defined with the [ServiceContract] attribute
    • Operation Contract: It defines the method that is exposed to the client for the information exchanging between server and client. It tells that functionality to be given to the client. It is defined with the [OperationContract] attribute.
    • Message contract: It is used to define the message elements that need to be passed, like a message header and a message body. It provides high-level security to messages as well. It is defined with the [MessageContract] attribute.
    • Fault contract: It is used to define the error that is raised by the service and handling of the error. It is defined with the [FaultContract] attribute.

6. What is difference between WCF and Web Service?

Web Service is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS.

WCF is also based on SOAP and return data in XML form. It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ. The main issue with WCF is, its tedious and extensive configuration. It is not open source but can be consumed by any client that understands xml or JSON. It can be hosted with in the applicaion or on IIS or using window service.

7. What are Contracts in WCF?

 The contracts are being used to provide the types of operations and structure that are being allowed between the client and service on which they agreed on for the process of communication. It mainly takes care of the type of operations, message form, input parameters and data, and response of the message. It is of many types that are mentioned below:

  • Data Contract: It is used to define the type of variable that will be used for the WCF service. A data contract is used to serialize and de-serialize the data. It helps in defining the format of data that needs to be passed from the service. It maps the common language runtime type to an XML schema. It is also referred to as a versioning system to manage the data. To define data contract, use [DataContract] and [DataMember] attribute.
  • Service Contract: It is used to define the operations that are being exposed to others. It acts as an interface for the service. It defines the name and namespace for the service. It is defined with the [ServiceContract] attribute
  • Operation Contract: It defines the method that is exposed to the client for the information exchanging between server and client. It tells that functionality to be given to the client. It is defined with the [OperationContract] attribute.
  • Message contract: It is used to define the message elements that need to be passed, like a message header and a message body. It provides high-level security to messages as well. It is defined with the [MessageContract] attribute.
  • Fault contract: It is used to define the error that is raised by the service and handling of the error. It is defined with the [FaultContract] attribute.

8. What are the various ways of hosting a WCF service?

There are 4 ways of hosting WCF Service:

Self-hosted: WCF services can be hosted in any managed application. This is the most flexible option because it requires the least infrastructure to deploy.

Managed Windows Services: This hosting option consists of registering the application domain (AppDomain) that hosts a WCF service as a managed Windows Service (formerly known as NT service) so that the process lifetime of the service is controlled by the service control manager (SCM) for Windows services. 

Internet Information Services (IIS): The IIS hosting option is integrated with ASP.NET and uses the features these technologies offer, such as process recycling, idle shutdown, process health monitoring, and message-based activation.

Windows Process Activation Service (WAS): Windows Process Activation Service (WAS) is the new process activation mechanism for the Windows Server 2008 that is also available on Windows Vista. It retains the familiar IIS 6.0 process model (application pools and message-based process activation) and hosting features (such as rapid failure protection, health monitoring, and recycling), but it removes the dependency on HTTP from the activation architecture.

9. What are the different bindings supported by WCF?

  • BasicHttpBinding: Basic web service communication. Exposes WCF services as legacy ASMX web services. Used for interoperability. No security by default.
  • WSHttpBinding: Web services with WS-* support. Supports transactions and reliable messaging.
  • WSDualHttpBinding: Web services with duplex contract and transaction support.
  • WSFederationHttpBinding: Web services with federated security. Supports transactions.
  • MsmqIntegrationBinding: Communication directly with MSMQ applications. Supports transactions.
  • NetMsmqBinding: Communication between WCF applications by using queuing. Supports transactions.
  • NetNamedPipeBinding: Communication between WCF applications on same computer. Supports duplex contracts and transactions.
  • NetPeerTcpBinding: Communication between computers across peer-to-peer services. Supports duplex contracts.
  • NetTcpBinding: Communication between WCF applications across computers. Supports duplex contracts and transactions.

10. What was the code name for WCF?

The code name of WCF was Indigo .

11. What is Throttling in WCF?

WCF provides a Throttling behavior to manage server load and resource consumption. As a result of this, performance of the WCF service can be improved.

Using throttling, one can restrict the number of instances or sessions that needs to be created at the application level.

You can set it in app.config

<behaviors>
    <serviceBehaviors>
      <behavior name="throttlingBehavior">          
        <serviceThrottling 
            maxConcurrentCalls = "50"  
            maxConcurrentInstances = "10"  
            maxConcurrentSessions ="20"/>
      </behavior>
    </serviceBehaviors>
</behaviors>

12. What are different attributes available in Throttling in WCF?

Following 3 attributes are available:

  • maxConcurrentCalls - Used to limit total number of calls which are currently in progress across all service instances. Its default value is 16.
  • maxConcurrentInstances - Showsnumber of InstanceContext objects that execute at one time across a ServiceHost. Its default value is Int32.MaxValue.
  • maxConcurrentSessions - It is a positive integer to limit the number of sessions a ServiceHost object can accept. Its default value is 10.

13. What is service proxy in WCF?

A Proxy in Windows Communication Foundation is a class that enables client applications to communicate with a service by sending and receiving messages. It actually encapsulates a number of service details like service path, service implementation technology, platform being used, communication protocol etc. as well as all the methods (signature only) of the Service Contract

14. What are different isolation levels in WCF?

Below are the 4 main isolation levels provided in wcf

  1. READ UNCOMMITTED:- Also known as dirty isolation level. It makes sure that corrupt Data cannot be read. This is the lowest isolation level.
  2. READ COMMITTED:- It ensures not to read the data that has been changed by any other application and is not yet committed. It is the default level.
  3. REPEATABLE READ:- Here locks are placed on all data and another transaction cannot read.
  4. SERIALIZABLE:- It will not allow other transactions to insert or update data until the transaction is complete.

15. What are different communication mode in WCF?

Request /response mode: The default message mode is this mode. This mode means that after the client sends a message to the server, the server will send a response to the client. In other words: the client will not continue to perform operations before receiving the service response

Even if the return type is void , it is also a request /response message exchange.

Simplex mode: One-way communication means that there is only one direction of communication, that is, from the client to the service, the service will not send a response, and the client will not expect a response. In this case, the client sends a message and then continues execution.

Duplex mode: The characteristic of duplex mode is that regardless of whether one-way message sending or request /reply message sending is used, both the service and the client can independently send messages to each other, providing an asynchronous experience for any party that must directly communicate with the customer or exchange messages (This form of two-way communication is very useful for services that include event-like behavior.)

In addition, to implement the duplex mode, a second interface must be created, which contains [method declaration called on the client side]; and it is necessary to design a callback contract and assign the type of the callback contract to the CallbackContract marking the ServiceContract attribute of the service contract Attributes.

16. What are the different types of transaction managers available in WCF?

Following 3 types of transaction managers available in WCF –

  • WS- Atomic Transaction
  • Light Weight
  • OLE Transaction

17. What is WCF RIA Service?

RIA services is a server-side technology that automatically generates client-side (Silverlight) objects that take care of the communication with the server for you and provide client-side validation.

It is an important framework to develop n-tier application for RIA (Rich Internet Application). 

The main object inside a RIA service is a DomainService, usually a LinqToEntitiesDomainService that is connected to a LinqToEntities model.

You may also like to read:

OOPS interview questions in C# (With Answers)

Commonly asked SQL server Interview questions and answers

Entity Framework Core Interview Questions with Answers.

DevOps interview questions and answers

XML Interview questions and Answers