WCF stands for windows communication foundation which is used to communicate with cross Platform application and to develop network distributed applications.
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.
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 Architecture
The WCF architecture consists of the following components.- Contracts.
- Service Run time.
- Messaging.
- 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
Service contracts
The service contracts nothing, but it defines the interface for the service. It can be defined as follows.
Syntax
[ServiceContract] public interface IService1 { // TODO: Add your service operations here }
Operation contract
It can be defined as
public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); }
Data Contract
It can be defined as follows.
[DataContract] public class Student { private string _Name; private string _City; [DataMember] public string Name { get { return _Name; } set { _Name = value; } } }
Fault Contract
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.
[ServiceContract] public interface IGetDetailsService { [OperationContract] [FaultContract(typeof(Student))] Student GetDetails(string Name); } [DataContract] public class Student { private string _Name; private string _City; [DataMember] public string Name { get { return _Name; } set { _Name = value; } } [DataMember] public string City { get { return _City; } set { _City = value; } } }
Message contracts
It can be defined as
[MessageContract] public class Person { [MessageHeader] public Operation Name; [MessageHeader] public string city; [MessageBodyMember] private Home Address; [MessageBodyMember] private Home Streat; [MessageBodyMember] public int age; }
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
Transport Channels
Protocol Channels
Implements SOAP based protocol by processing and possibly modifying message. E.g. WS-Security and WS-Reliability.
Services can be hosted or executed, so that it will be available to everyone accessing the client. The WCF service can be hosted by the following mechanism.Activation and Hosting in WCF
IIS
Windows Activation Service
Self-Hosting
The WCF service can be self-hosted as a console application, Win Forms or WPF application with a graphical UI.
Windows Service
WCF can also be hosted as a Windows Service, so that it is under the control of the Service Control Manager (SCM).
Advantages of WCF
- 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.
Please refer my following articles for complete understanding
Post a Comment