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
- The Service
- One or more Endpoints
- 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
- Create a service Contract
- 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:
- 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.
great comparison!
Thank you.
Nice Post … it is easily understand who new to WCF
Thank you for nice comment.
gd.nic descriptn
I m glad to know that you liked it.
Thanks a lot for this post. It helped me lot to understand the differences between WCF and web service,