Search This Blog

Sunday, May 1, 2011

Windows Communication Framework - Basics


The below is my conclusion regarding wcf, may help you in starting developing wcf applications...


System.ServiceModel

Service => is a dll and have
{
service contracts => The interface that client can expose
operation contracts => the methods that client can expose
data contracts => the data types that will be transferred b/w client and service
Member contracts => the data members that will be transferred b/w client and service
}

Serivice => is described by the endpoints and a service can have multiple endpoints

EndPOint (ABC)=> A (Address), B(Binding/), C(Contract)
  refer http://www.wcftutorial.net/EndPoint.aspx for more info...


Visula Studio Templates

=> WCFClass Library ( it is service library)
=> WCF Console Application ( It will have service host application + service library)

See how simple it is in WCF. Microsoft is making everything simple. Cording to its scope: common behaviors affect all endpoints globally, service behaviors affect only service-related aspects, endpoint behaviors affect only endpoint-related properties, and operation-level behaviors affect particular operations.

Service Configuration:
To configure A Service in any application’s config file:
1. Add End Points for the service (Address(relative), Binding, and Contract)
2. Add a Base Address for the Service Endpoints( under “host” tag)
3. Add a service behavior ( with meta data access settings) and set this to the above added service
4. Add one more endpoint for Meta Data Exchange with contract as “IMetaDataExchage”

Main Contracts
http://www.wcftutorial.net/Contracts-and-Service-Host.aspx

 => Message Contracts
 => Fault Contracts
Service needs to be hosted in an Application, and when the host application starts running, clients can access the service.

Microsoft Tools for service hosting and testing:
1. Wcfsvchost => tool for hosting the service
2. Wcftestclient => will expose the service contract and will test the operations.

Service Hosting:
1. Self Hosting => Create an exe with the service reference ( service code here itself). Make sure App.config file have all details( Metadata informations). Use ServiceHost to host the service( will bring into memory) when the exe starts running.

2. IIS Hosting => create a wcf website ( which will give .svc file). Put the folder into IIS folder( through virtual directory). From IIS you can open the svc file in browser.

3. WAS

4. Windows Service Hosting

Service Clients:
Service is hosted, now we need to implement the proxy class for the client. There are different ways of creating the proxy
Using SvcUtil.exe, we can create the proxy class and configuration file with end points.
Adding Service reference to the client application.
Implementing ClientBase<T> class - Here we need to implement the interface with generic parameter T as the service contract. This proxy class will implement all methods. Client will use this proxy class

*Note => the first 2 mechanisms, need to update if service got updated. But if we are using clientbase proxy class, the proxy no need to updated if service got updated, so this is the best method for the client to access service.

1. Add the service reference and get the proxy class for the service contract.

2. Right click the service reference to see the service details and the proxy class generated.

3. Use the proxy to access the services

No comments:

Post a Comment