What is WCF (Window communication Foundation)?


What is WCF (Window communication Foundation)?

WCF is the .net framework Communication technologies. It is the combination of following technologies:

  • .Net Remoting
  • MSMQ(Microsoft message queuing)
  • Web services
  • COM+

Uses of  WCF

  • It is used to communicate between other applications which has been developed on other platforms and using other Technology.

For example, if  I have to transfer data from .net platform to other application which is running on  other OS (like Unix or Linux) and they are using other transfer protocol (like WAS, or TCP)

Then it is only possible to transfer data using WCF.

Advantages:

  • Here is no restriction of platform, transfer protocol of application while transferring the data between one application to other application.
  • Security is very high as compare to web service

What is the difference between web service and WCF ?

1. Web service use only HTTP protocol while transferring data from one application to other application.

But WCF supports more protocols for transporting messages than ASP.NET Web services. WCF supports sending messages by using HTTP, as well as the Transmission Control Protocol (TCP), named pipes, and Microsoft Message Queuing (MSMQ).

2. To develop a service in Web Service, we will write the following code

[WebService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Test(string strMsg)
{
return strMsg;
}
}

To develop a service in WCF, we will write the following code

[ServiceContract]
public interface ITest
{
[OperationContract]
string ShowMessage(string strMsg);
}
public class Service : ITest
{
public string ShowMessage(string strMsg)
{
return strMsg;
}
}

3. Web Service is not architecturally more robust. But  WCF is architecturally more robust and promotes best practices.

4. Web Services use XmlSerializer but WCF uses DataContractSerializer. Which is better in performance as compared to XmlSerializer?

5. For internal (behind firewall) service-to-service calls we use the net:tcp binding, which is much faster than SOAP.

WCF is 25%—50% faster than ASP.NET Web Services, and approximately 25% faster than .NET Remoting.

For more detail, check this link   http://msdn.microsoft.com/en-us/library/aa738737.aspx


WCF Frameworks Architecture

WCF is the combination of 3 parts

  1. The Service
  2. One or more Endpoints
  3. Environment in which to host the service.

A service is a class that is written in one of the .NET-compliant languages. The class can contain one or more methods that are exposed through the WCF service. A service can have one or more endpoints. An Endpoint is used to communicate through the service to the client.

Endpoints themselves are also made up of three parts. These parts are usually defined by Microsoft as

the ABC of WCF.

➤ “A” is for address.

➤ “B” is for binding.

➤ “C” is for contract.

  • Address is a URL, which points to the location of the services.
  • Binding indicate how this end point can be accessed. It determines how the communication is done. It indicates regarding binding protocol in Service.
  • Contract defines the protocol, how the client should communicate with your service. It describes the parameter and return values for a method.

Creating WCF Services

You must have to perform 2 main tasks

  1. Create a service Contract
  2. Create a data Contract

The service contract is really a class with the methods that you want to expose from the WCF service.

The data contract is a class that specifies the structure you want to expose from the interface.

After you have a service class in place, you can host it almost anywhere

Hosting  options for WCF  Service

➤ Console applications

➤ Windows Forms applications

➤ Windows Presentation Foundation (WPF) applications

➤ Managed Windows Services

➤ Internet Information Services (IIS) 5.1

➤ Internet Information Services (IIS) 6.0

➤ Internet Information Services (IIS) 7.0 and the Windows Activation Service (WAS)

Binding in WCF

WCF provides nine built-in bindings:

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

7 thoughts on “What is WCF (Window communication Foundation)?

  1. lee June 8, 2011 / 8:52 pm

    great comparison!

  2. Venkatesh August 16, 2011 / 5:09 am

    Nice Post … it is easily understand who new to WCF

  3. puja July 24, 2012 / 9:38 am

    gd.nic descriptn

    • Chandra Dev July 24, 2012 / 10:59 am

      I m glad to know that you liked it.

  4. Thirunavukkarasu April 13, 2016 / 5:50 am

    Thanks a lot for this post. It helped me lot to understand the differences between WCF and web service,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.