Sunday, December 20, 2009

Basics of Window Communication Foundation(WCF)

csharpwithdj.blogspot.com
Basic WCF Concept and Terminologies


Windows Communication Foundation was official released with .NET 3.0 a couple of months ago. For those people who're doing connected, distributed systems or are in any way interested in communication aspects of systems, this ought to be a God-send. WCF basically rolled all the different Microsoft messaging formats into one, making it extremely easy to architect the communication layer of simple to complex applications. This tutorial aims to explain the basic concepts behind the common terminology used in WCF development and design.


WCF Programs

WCF programs are basically divided into 3 different types of programs. They are common known as

• Clients

Clients are program that consumes the services, they are normally the ones that initiate the messenging to the service. Depending on the designed architecture of your application, it is possible that a service behaves as a client as well.

• Services

Services are the programs that offers the services to the consumers. They are the ones that react and process the messages, similar to the backend of the application. They can be viewed as the equivalence of web services in .Net 2.0.

All services have to have endpoints specified in order to work. A good way to remember proper endpoint configurations is ABC. A being Address, B being Binding and C being Contracts.

o Address

Address are the expose points of services. Services have to tell the world that where they are via addresses.

o Bindings

Bindings will describe to the world on how they will communicate with the world. They contain information such as transport way, how they are encoded, are they reliable etc.

o Contracts are of (but not necessary all have to be present) 3 different kinds

 Service Contract

Describes what the service does.

 Data Contract

Define custom messaging structure.

 Message Contract

Define the message format that is passed between services.

• Intermediaries

Intermediaries are programs that act as "middle-man", their basic roles can be similar to providing a firewall, routing, gateway etc. They are commonly invisible to the client and services.

Messages

All services and clients communicate via messages, which are made up of one body, and one or more header. All WCF messages are XML formatted and transport neutral. In other words, you can specify different forms of transport (HTTP, MSMQ, Named Pipes etc) for different messages. Within each application, you can specify different messaging transport depending on the communication needs of the system. Basically, messages can be divided into

• Simplex

One way messaging. Simplex in short means "fire and forget"

• Duplex

Asynchronous two-way messaging. In short this means that once fired, the application will carry on doing its own thing. Upon the return results, it will then handle it.

• Request Reply

Synchronous 2 way messaging. This is the common communicate method whereby you'll fire a request, and wait for the response before continuing.

Channels

Before a client and service can talk to each other, they have to go through a channel. Imagine a channel as a pipe, with one end being the input message and the other end with the results of the message. There're different channels that can be stacked onto each other, they are commonly known as Channel Stacks. They can be of these different types:

• Reliable Sessions

• TCP Transport

• Binary Message Encoder

• Windows Security

• Request Reply

The way in which messages are sent through the pipe (Channel) is known as a Transport and they way at which they are encoded are known as Encodings. Transport can be made up of the following:

• HTTP

• TCP

• MSMQ

• Named Pipes

No comments: