What is WCF?
Windows Communication Foundation is a framework for building service-oriented applications. It provides a common platform for all .NET communication. It is used for sending asynchronous messages from a service to another. WCF has interoperability feature, which is a fundamental characteristic of it. It combines feature of MSMQ, Remoting, Com+ and Web Services.
Given below are the components of WCF service.
- WCF Service
- WCF Host
- WCF Cleint
Concept of WCF
Below are some of the fundamental concepts of WCF.
- EndPoint
- Binding
- Contract
- Message
- Channel
- WCF Client
EndPoint
EndPoint is responsible for all communication in WCF Services. WCF Service exposes a collection of Endpoint. Each Endpoint defines address where message needs to send or received. It also specifies how messages will be sent.
Endpoint consists of three components, as described below.
- Address
It specifies exact location where your service is hosted as URL, which will be used by client for connecting to service. Below is the example for the same.
http://localhost:8090/ServiceA/FirstService.svc
- Binding
It specifies a way of communication for the client with service endpoint. It specifies which protocol will be used for communicating with specified Endpoint.
Below are several protocols available to communicate with Service.
- Contract
It is basically a collection of endpoints which specifies what type of functionality the endpoints are going to expose to the client. Generally it contains the name of the Interface.
Below is a sample for Endpoint
- <system.serviceModel>
- <services>
- <service name="FirstService" behaviorConfiguration=”FirstServiceeBehavior ">
-
- <endpoint
-
- address="http://localhost:8090/ServiceA/FirstService.svc " contract="IFirstService "
-
- binding="wsHttpBinding "/>
-
- </service>
-
- </services>
-
- <behaviors>
-
- <serviceBehaviors>
-
- <behavior name="FirstServiceBehavior ">
-
- <serviceMetadata httpGetEnabled="True "/>
-
- <serviceDebug includeExceptionDetailInFaults="true " />
-
- </behavior>
-
- </serviceBehaviors>
-
- </behaviors>
-
- </system.serviceModel>
Message
It is a communication unit between client and service which contains several parts, including body and headers. Messages are sent and received from client and service for all types of communication.
Channel
Channel is a medium between client and service for communication. There are different types of channels which gets stacked and are known as Channel Stacks.
We can categorize channels in the following categories:
Protocol Channels: These are responsible for implementing and supporting security, transaction and reliable messaging. These also modify and transform messages to make it compatible to a wire level.
Transport Channel: These are responsible for sending and receiving messages using transport protocol. It supports HTTP, TCP, MSMQ, Named Piped and Peer to Peer transport protocols.
Hosting
It refers to hosting of WCF service which is done through self- hosting, IIS Hosting, WAS Hosting and Windows Service Hosting. In this the Host loads the service configuration endpoints and starts the listeners handling the incoming request
WCF Client
It is a client application which gets created and exposes the service operations in form of method. And a client application is a managed application which uses WCF Client with another applications.
Below is the detail for creating the WCF Client,
- Get the Proxy class and service end point information using svcutil.exe
- Call operations.
- Dispose the WCF Client Object
Metadata
It helps for interaction between a client and a WCF service. It can be set in the service by enabling the ServiceMetadata node inside the serviceBehavior node of the service configuration file.
Advantage of WCF
- One of its key features is interoperability, that is, a single platform used to exchange information using various network protocols and platforms
- WCF provides better security and reliablity as compared to web services or ASMX services. Security is a key element in any Service Oriented Architecture (SOA), and it is provided in the form of auditing, authentication, authorization, confidentiality and integrity of messages shared between the client and the service.
- It offers scalability and support for up-coming web service standards.
- It contains integrated AJAX and support for JASON, and also contains a default security mechanism which is extremely robust.