Steps Towards Windows Communication Foundation: Part 2

Introduction:

My previous article was an introduction to WCF, including it's history. This article is about some basics of Windows Communication Foundation .

Windows Communication Foundation:

WCF is nothing but the distributed programming between .Net to any user with their own proprietary methods. For a .Net user today to develop a service WCF is the only preferred way. In general you can say:

WCF=.Net Remoting + Web Service + New Standard.

WCF in simple terms:

  1. One stop-shop for service.
  2. Consistent object model.
  3. Great feature.

Next Generation of ASMX is WCF:

The unified framework for rapidly building service-oriented applications. WCF is provided as a framework with it's own runtime & libraries. A .Net component is executed using CLR but the request-response will be handled by the WCF framework. It is built on the top of the .Net framework.

How WCF provides this communication environment?:

Every WCF application that we develop includes the following structure/components that provides it's communication model.

1. Endpoint:

This is a structure which provides info about service (program). Endpoint includes three things and they are easily referred to as 'ABC'.

A- Address:

A network address where the endpoint resides.

Example:

http://csharpcorner.com/services/stepwcf.svc.
Net-tcp://192.168.100.5/myservice/stepwcf.svc

B- Binding:

Specify how the endpoint communicates with the world. As well defines the following three things.
  1. Transport (eg. Http , Tcp)
  2. Encoding (Text , Binary)
  3. Security Option(SSL, Message Security)

C- Contract:

Specify what Endpoint communicates.
  1. Message exchange pattern (One-way, Duplex).
  2. Service Operation.
  3. Service Behavior (Exchange Meta-Data, Impersonate Authorization).

2. Service Contract:

This is the most important attribute; it adds all WCF functionality to our component so that it can be exposed as a contract for the Endpoint.

Example:

[ServiceContract]
Class Employee
{
}

3. Operation Contract:

Again an attribute which makes an operation exposed in our service. This attribute is written to method of [ServiceContract] Class.

Example:

[ServiceContract]
Class Employee
{
[OpearationContract]
Void Delete();
}

If we do not write an operation contract then those methods are accessible only within the .Net class; not to the outside world.

4. Data Contract:

In operationcontract or WCF enabled methods if we are using any complex types to represent either Data/Action then we must declare them as DataContract.

Example:

[OpearationContract]
Public void Add(Job j);
{}

[DataContract]
Class Job
{}

Conclusion:

In this article we have seen some basic steps of the Windows Communication Foundation. In my next article we will see: how to create our own service using WCF? How to host this service? How to consume the service created using WCF?

Up Next
    Ebook Download
    View all
    Learn
    View all