Category Archives: WCF

What is WCF Reliable Messaging?

WCF Reliable Messaging makes web services more reliable. It addresses the following problems:

  • A call to a web service does not make because the networks are not perfectly reliable as they suffer congestion and may drop signals.
  • OR the service response does not make it back to the client.

If I make multiple calls to the web service and the calls do not reach to the service in the same order that i made them there is a problem.

WCF reliable messaging makes sending messages reliable and ordered over unreliable network.


Client: Hello Service!
Service: What may I help you!
Client: Message#1
Service: Message#1 received!
Client: Message#2
[No response from Service]
Client: Message#2
Service: Message#2 received!
Client: Good bye!
Service: Bye!

Explanation: The Client did not get a response when it send message#2. The reason may be the service did not get the message#2 or the service got the message but the response did not make it back. Whatever the reason, The client tries again and send the Message#2. if the service received the Message#2 twice it will ignore the second message.

What are Contracts in WCF?

A Contract is basically an agreement between the two parties i.e. Service and Client. There are two types of Contracts in WCF.

Behavioral Contracts

  • Service Contract:- Service contract describes the operation that service provide. A Service can have more than one service contract but it should have at least one Service contract. A Service Contract can be define using [ServiceContract].

Public interface IBookOrder
//do some stuff

  • Operation Contract:- The [OperationContract] attribute declares that a method is an operation in a service contract. Only methods attributed with the [OperationContract] are exposed as service operations.

bool CheckOrder(int ordernumber);

  • Fault Contract:- It is used to communicate error information from a service to a client.

Structural Contracts

  • Data Contract:- A data contract describes the data that is to be exchanged between client and service. The service and the client do not need to agree on the types, but they do need to agree on the data contract.


Public class BuyStock


  • Message Contract:- Message contracts provide the ultimate control over the formatting of the SOAP messages. A message contract provides the level of interoperability you would need when you need to communicate with clients or other systems.

Public class BuyStock
Public string Title;
Public decimal Cost;

What are different types of hosting options available for WCF Services?

WCF provides two types of hosting:

Hosting in a Managed Application (Self Hosting)

  • Windows Application
  • Windows Service
  • Console Application

Hosting on Web Server

  • IIS 6.0 supports only HTTP
  • Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP, MSMQ, NamedPipes.

What is difference between BasicHttpBinding and WsHttpBinding.


  • It is based on SOAP 1.1 specification.
  • No support for reliable Messaging.
  • No support for transactions.
  • It is a bit faster because security is disabled by default.


  • It is based on SOAP 1.2 specification.
  • It supports reliable messaging.
  • It supports atomic and distributed transactions.
  • As it supports advanced security options and its enabled by default, so it’s a bit slower than BasicHttpBinding.

What is a WCF Binding? How many different types of bindings available in WCF?

Bindings in WCF actually defines that how to communicate with the service. Binding specifies that what communication protocol as well as encoding method will be used. Optionally, binding can specify other important factors like transactions, reliable sessions and security.

Different types of bindings available

  1. BasicHttpBinding :
    •  It is suitable for communicating with ASP.NET Web services (ASMX)-based services.
    • This binding uses HTTP as the transport and text/XML as the default message encoding.
    • Security is disabled by default.
    • It is fairly weak on interoperability.
  2. WSHttpBinding
    • Defines a secure, reliable, interoperable binding suitable for non-duplex service contracts.
    • It uses HTTP and HTTPS transport for communication.
    • Reliable sessions are disabled by default.
  3. WSDualHttpBinding
    • This binding is same as that of WSHttpBinding, except it supports duplex service.
    • WSDualHttpBinding reliable sessions are enabled by default.
  4. WSFederationHttpBinding
    • This binding is provided by the WSFederationHttpBinding class.
    • It is a specialized form of WS binding and provides support to federated security.
  5. NetTcpBinding
    • This binding provides secure and reliable binding environment for .Net to .Net cross machine communication.
    • It uses TCP protocol for communication be-tween two machines with in intranet.
    • It encodes the message in binary format. This is faster and more reliable binding as compared to the Http protocol bindings.
  6. NetNamedPipeBinding
    • It uses NamedPipe protocol and provides full support for SOAP security, transaction and reliability.
    • By default it creates communication stack with WS-ReliableMessaging for reliability, transport security for transfer security, named pipes for message delivery and binary encoding.
  7. NetMsmqBinding
    • This binding provides secure and reliable queued communication for cross-machine environment.
    • Queuing is provided by using MSMQ as transport.
  8. NetPeerTcpBinding
    • This binding provides secure binding for peer-to-peer environment and network applications.
    • It uses TCP protocol for communication.
    • It provides full support for SOAP security, transaction and reliability.

What are the Endpoints in WCF? or Explain ABCs of endpoint?

The Relationship between Address, Binding and Contract is called endpoints.

A service endpoint has three basic elements or also called ABCs of an endpoint i.e. Address, Binding and Contract.

  • Address: Address is the URL that identifies the location of the service.
  • Binding:  Binding defines how the service can be accessed.
  • Contract:  Contract identifies what is exposed by the service.

What is the difference between WCF and Web services?

Web service

  • ASMX web service uses SOAP over HTTP only for sending and receiving messages.
  • ASMX web service can be hosted in IIS only.
  • ASMX web service uses XmlSerializer.
  • ASMX web service provide limited security.

WCF service

  • WCF service uses SOAP over any transport protocol (HTTP, TCP/IP, MSMQ, Named Pipes etc) for sending and receiving messages.
  • WCF service can be hosted in IIS, WAS (Window Activation Services), Console, WinNT service and WCF provided host.
  • WCF service uses DataContractSerializer.
  • WCF service follow a Consistent programming model.

Explain WCF Features.

Transactions A transaction is a unit of work. A transaction ensures that everything within that transaction either succeeds as a whole or fails as whole. For example, if a transaction contains three items of work to perform, and during the execution of that transaction one of those items fails, then all three fail. The transaction succeeds only if all three statements of work succeed, unless a Checkpoint is issued. You commonly see this in database operations.
WCF incorporates this same transactional processing into its communication.
Hosting WCF hosting allows services to be hosted in a handful of different environments, such as Windows NT Services, Windows Forms, and console applications, and well as IIS (Internet Information Services) and Windows Activation Services (WAS).
Hosting a service in IIS has added benefits in that the service can take full advantage of many of the native IIS features. For example, IIS can control the starting and stopping of the service automatically.
Security What good would Windows Communication Foundation be without security? Trust me on this, WCF certainly isn’t lacking in this department. Everything from messages to clients and servers get authenticated, and WCF has a feature that ensures messages aren’t messed with during transit. WCF includes message integrity and message confidentiality.
WCF also enables you to integrate your application into an existing security infrastructure, including those that extend beyond the standard Windows-only environments by using secure SOAP messages.
Queuing If you are at all familiar with MSMQ (Microsoft Message Queuing), this topic will sound familiar. WCF provides queuing, allowing messages to be safely stored, providing a consistent state of communication. Queuing collects and stores sent messages from a sending application and forwards them on to the receiving application. This provides a safe and reliable message delivery mechanism.