Here in my first series of article I will be sharing top to bottom of the WCF (The Indigo).
WCF is the great way to approach large multi-system message based communication. It seamlessly support Transaction Management, Security Implementation, Exception and Fault handling. Concurrency management etc.
Usage of WCF comes with the great amount of flexibilities' to handle. WCF is a framework for services. The user can Create, Configure, Host and consume the services. All the services are mutually agreed on SOAP concept and communicating between WCF based clients.
WCF has mainly two categories of classes:
1. Service Model Class (Handles Service Configurations & Validations).
2. Channel Classes (Handles mode of communication and related functionalities).
Each WCF service can be associated with one ore more service endpoints. One service can be hosted in WCF with different mode of communication channel. Depending upon the usage and target client WCF Service can be configured (I will focus this more on this in my up coming articles).
Configuring endpoints require (A, B & C):
1. Address ('A') = Where?
2. Binder ('B') = How?
3. Contract ('C') = What?
Address: The address means the URL/URI where the service is located. Where is the service located?
Binder: The mode ofcommunication. How to communicate with the service?
Contract: The Service. What is my service?
With the XML Based configuration approach OR with the help of coding we can configure the endpoints.
Hosting WCF Service
WCF Service is can be segregated in to two parts normally:
1. Service Contract
2. Service Implementation
In above example, I have created a sample service with just one operation i.e. MyOperation with one parameter. As you can see i have used Attributes. ServiceContract attributes comes under System.ServiceModel. Including this DLL as in reference list is must for WCF Service Host and WCF Consumer.
You can create multiple operations by using "OperationContract" attribute. By specifying OperationContract attribute means the operation will be available for WCF Service and the WCF client can consume that.
In above example I have created "HelloIndigoService" which is implementing our "IHelloIndigoService" service interface.
WCF Service can be self-hosted service but to start with we will see simple .NET consol based hosting mechanism.
Attributes of Service Contract
Using declarative model you can apply different parameters (as per your requirements) on WCF Service Contract:
Name:
Name property is impacting on WSDL generation. With the help of this property user can specify XML Root Tag name of WSDL. Unlike the older messaging mechanisms, WCF provides great deal of control over WSDL generation. I will discuss more about forming the WSDL with OperationContract later in this article.
Namespace:
Namespace is also related with WSDL formation. After you generated the proxy of WCF Service; the given namespace will be appear in WSDL Namespace.
ProtectionLevel:
User needs to use ProtectionLevel according to their service requirements and the operations that service will be exposing. There are three different ProtectinLevels are available.
1. None:
2. Sign: The protected part is signed digitally to ensure the temper less submission of data
3. EncryptAndSign: This will encrypt data before sighed it digitally.
More details on ProtectionLevel : http://msdn.microsoft.com/en-us/library/aa347692.aspx