WCF Interview Questions and Answers

WCF is a service related framework developed by Microsoft Corporation. It  provides better facilities than traditional web service. Here is some common important questions and answers in WCF. Hope it will help you to build successful carrier.

What is the full meaning of WCF?
Full meaning of WCF is Windows Communication Foundation.

What is WCF?
Windows Communication Foundation or WCF is a framework for building service oriented applications. By using WCF we can transfer data as asynchronous message.

What are the components of WCF?
WCF Service is composed of three components:

  1. Service Class – implements the service needed
  2. Host Environment -is an environment that hosts the developed service
  3. Endpoints -are the connection points for the clients to connect to the service. Clients find the end points through three components like service contract, binding, and address

What is ABC?
ABC means Address, Binding and Contract. Without ABC there is no WCF. The WCF mantra is ABC. ABC is the key to understanding how a WCF service endpoint is composed.

  • A stands for Address(Where?)
  • B stands for Binding(How?)
  • C stands for Contract(What?)

What is Address, Binding, Contract in WCF?
Address (Where?): Where is the service? Specifies the location of the service which will be like http://Myserver/MyService.Clients
Binding (How?): How do I talk to the service? Specifies how the two parties will communicate in terms of transport and encoding and protocols.
Contract (What?): What can the service do for me?

What is EndPoint in WCF
In application all types of communication with the WCF will occur via the endpoints. It specifies a Contract that defines which methods of the Service class that will be accessible via the endpoint. Each endpoint may represent a different set of methods. It also defines a binding that specifies how a client will communicate with the service and the address where the endpoint is hosted.

What are the Types of Contracts in WCF?

  1. Service Contract
  2. Operation Contract
  3. Data Contract

What is Service Contract?
It defines the methods of the service. A sample C# codes for WCF service contract is given bellow:

[ServiceContract]
public interface IOperation
{
    [OperationContract]
    double Add(double i, double j);
    [OperationContract]
    double Sub(double i, double j);
}

What is Operation Contract?
It defines the method. A sample C# codes for WCF operation contract is given bellow:

[OperationContract]
double Add(double i, double j);

What is Data Contract?
IT defines the data types used by the service methods. A sample C# codes for WCF data contract is given bellow:

public class ComplexNumber
{
    private int RealNumber;
    private int ImaginaryNumber;

    [DataMember]
    public int RealNumber { get; set; }

    [DataMember]
    public int ImaginaryNumber { get; set; }
}

What is the Difference between Web Service & WCF?
The differences between web service and WCF are given bellow:
Web Service

  1. It use HTTP
  2. It is only used in web application
  3. Unhandled exceptions are return to client as SOAP fault
  4. It use XmlSerializer
  5. Accessed through HTTP
  6. It can be hosted in IIS
  7. [WebService] attribute has to be added to the class
  8. [WebMethod] attribute represents the method to client

WCF

  1. It use HTTP, TCP IP
  2. It can be used in web, desktop, Console, Mobile applications
  3. Unhandled exceptions are not return as SOAP fault. Configuration setting is provided
  4. It use DataContractSerializer which is better in Performance as compared to XmlSerializer
  5. Accessed through HTTP, TCP, MSMQ, P2P
  6. It can be hosted in IIS, windows activation service, Self-hosting, Windows service
  7. [ServiceContract] attribute has to be added to the class
  8. [OperationContract] attribute represents the method to client

What are Various Ways of Hosting WCF Services?
We can host a WCF Service in three major ways:

  1. IIS -host in application domain or process provided by IIS Server
  2. Windows Activation Service (WAS) -host in application domain and process provided by WAS
  3. Self-hosting -hosting in its own application domain

What are different binding supported by WCF?
WCF support Built- in bindings and custom bindings. When the built in or system provided bindings are not suited for the requirement we can use custom bindings.
The system provided bindings are:

  • BasicHttpBinding -uses HTTP for transport
  • WSHttpBinding -used for non duplex services
  • WSDualHttpBinding -used for Duplex services
  • NetTcpBinding -used for cross machine communication
  • NetPeerTcpBinding -used for multiple machine communication
  • NetMsmqBinding -queued binding Used for multiple machine communication.

What are the advantages of hosting WCF Services in IIS as compared to self-hosting?
There are two main advantages of using IIS over self-hosting:-
Automatic Activation
IIS provides automatic activation facilities. There is no need to run the service in advance. When any message is received IIS run the service and fulfills the request. But in self hosting the service should always be running.
Process Recycling
When IIS finds that a service is not healthy (memory low etc.) then IIS recycles the process without losing any data.
But if we want to provide these two feathers in self hosting we need to write lot of code that is time consuming.

What is a duplex contract in WCF?
WCF allows duplex messaging pattern. Services can communicate with client through a callback. Duplex messaging in WCF can be done over different transports, like TCP, Named Pipes and even HTTP

What are the various programming approaches for WCF?
Programming approaches for WCF:

  • Imperative: – We can use different programming languages for implementing service logic
  • Configuration based– We can use Config files to accomplish a task and end points along with security settings
  • Declarative -We can use Attributes for declaration for behaviors and contracts

Explain transactions in WCF.
Transactions in WCF allow several components to concurrently participate in an operation. Transactions are a group of operations that are atomic, consistent, isolated and durable. WCF has features that allow distributed transactions. Application config file can be used for setting transaction timeouts.

Explain volatile queues and Dead letter queues.
Volatile queues are non transactional queues. It is used for storing messages. They are stored in memory and not used in transactions. If we shut down the machine the queue will be deleted. They don’t guarantee the transfer of messages.
Dead letter queues are used for failed or dead messages. When a message delivery fails, it is stored in a dead letter queue. MSMQ has two types of dead letter queues recording failed messages for transactional systems and non transactional systems.

Comments

  1. By McCulloch

    Reply

  2. By Tianna Morris

    Reply

  3. By Nottingham

    Reply

  4. By Buck

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *