Previously, WCF was known for the Indigo service and later on with .Net Framework is known as WCF, WCF was first introduced with .Net Framework 3.0 in 2006 later on its become the most popular programming language for network distributed application because it provides all combined features of Web service, Remoting, MSMQ and com+ on a single platform without using different services for different requirements.
Let us understand with the following diagram.
From the above diagram, I am trying to give you a message that WCF is the common technology to provide the feature of all technologies being used to communicate for different purposes.
Why WCF ?WCF Provides a wide range of features including communication protocol support, security etc. Let us consider the following example.
From the above diagram I am trying to explain that WCF Service can exchange data or message in any format that is SOAP, Binary using a wide range of communication protocol such as HTTP,TCP etc.
WCF ArchitectureThe WCF architecture consists of the following components.
- Service Run time.
- Activation and Hosting .
Contracts in WCF
The following are the contracts which are available in WCF.
- Service contracts
- Data contracts
- Message contracts
- Fault Contract
- Operation contract
- Policies and Binding
It can be defined as
It can be defined as follows.
Fault contract is used to handle the exception and know the cause of the error which occurs in WCF service. When we develop a managed application or service, we will handle the exception using try-catch block. But these exceptions handling are technology specific.
In order to support interoperability and client will also be interested only in what went wrong? Not on how and where the error was made.
The following is the syntax to raise the custom error in WCF.
It can be defined as
Policies and Binding in WCF
Specify conditions required to communicate with a service, e.g., security requirement to communicate with a service, protocol and encoding used for binding.
Service Run-time in WCF
- Throttling Behavior
- Error Behavior
- Metadata Behavior
- Instance Behavior
- Transaction Behavior
- Dispatch Behavior
- Concurrency Behavior
- Parameter filtering
- Message inspection
Error Behavior: Specifies what occurs when internal error occurs on the service.
Metadata Behavior: Tells how and whether metadata is available to the outside world.
Instance Behavior: Specifies how many instances of the service have to be created while running.
Transaction Behavior: Enables the rollback of transacted operations if a failure occurs.
Dispatch Behavior: Controls how a message is processed by the WCF Infrastructure.
Concurrency Behavior: It's used to control how many threads can access a given instance of service.
Parameter filtering: It filters the message headers and executes preset actions based on the filters of the message headers.
Message inspection: It's used to inspect a specific part or all parts of the message through service.
Messaging in WCF Service
- Transport Channels
- Protocol Channels
Activation and Hosting in WCF
Windows Activation Service
The WCF service can be self-hosted as a console application, Win Forms or WPF application with a graphical UI.
WCF can also be hosted as a Windows Service, so that it is under the control of the Service Control Manager (SCM).
- Support for different protocols
- Security over transport as well as Message level
- Easy to implement MSMQ and REST Service.
- Load balancing & support scaling.
- It can control concurrency.
- It can be hosted on IIS, WAS, Self hosting, Windows services.
- Multiple Message Patterns.
- Unhanded Exceptions does not return to the client as SOAP faults. WCF supports better exception handling by using Fault Contract.