Thursday, August 16, 2007

WCF Concepts and Constructs

We will look at the Main Concepts, main consituent components of what forms SOA and specifically we will discuss Messages, Channels, Services and Behaviours.

1. Messages

When we talk about messages, the first things we need to know is its structure - it consists of a SOAP Envelope, SOAP Header and a SOAP Body.

SOAP Envelope

This is the outermost element and container for Header, Body, Name and Namespace.

SOAP Header

This contains important information not directly related to the message but optional information e.g. School Name for packets containing Student Info. This SOAP Header can also have Child elements called 'Header Blocks' - optional header info.

SOAP Body

This is the crux of the message i.e. basically collection of data items to be used by the SOAP receiver.

A Basic XML sample of Message

<env:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<env:Header>
<o:order xmlns:o="http://www.MySite.com/order" env:mustUnderstand="true">
<o:orderreference>591aef96-0c0d-4534-a1d2-4253b910b0b6</o:orderreference>
<o:orderdate>05/15/2006</o:orderdate>
</o:orderreference>
<p:purchaser xmlns:o="http://www.MySite.com/purchaser" env:mustUnderstand="true">
<p:name>Peter Spano</p:name>
<p:creditcardnum>1234-5678-9012-3456</p:creditcardnum>
</p:orderreference>
</env:Header>
<env:Body>
<c:price xmlns:c="http://www.MySite.com/bookcost">
<c:cost>
<c:retailcost>$49.99</c:retailcost>
<c:salecost>$39.99</c:salecost>
</c:cost>

</c:price>
<q:quantity xmlns:q="http://www.MySite.com/quantity">
<q:orderquantity>1</q:orderquantity>
</q:quantity>
<t:title xmlns:t="http://www.MySite.com/title">
<t:booktitle>WCF - The Book</t:booktitle>
</t:title>
</env:Body>
</env:Envelope>


SOAP Envelope



















Messaging Programs

In previous post I taked about SOAP Receivers, what it is and besides it what are the other messaging programs. Let's have a look:

Client --> This is the program which initiates message communication with a service.

Service --> This provides a service to the client and can also 'chain on' to another service.

Further, 2 Clients can call the same 'End Point' of the same Service and the sessions are isolated from each other by the service. Cool eh!

Communication Patterns are either Simplex i.e. One way transmission, Duplex i.e. both Client and Service can send simlutaneously or two way and finally Request-Reply where Client sends a request and waits for an answer.

2. Channels


This is the medium through which messages are exchanged. The process is somewhat liek this:


--> Client Establishes a channel.


--> Service accepts the channel request.


--> Client Sends message/s.


--> Service sends a reply back to the client.



Channel Stack - When each channel performs a specific function during message communication, then number of such channels are called a channel stack. Examples of such Specific functions include:


Security - Transport Security (https) and Message Security (SOAP)


Interop - WS, .NET , MSMSQ


Message Pattern - Simplex, Duplex etc.


Transport - http: Communication Info is not important, tcp: Communication info is important, Named pipes: Single Machine comms between processes, MSMQ: Reliable Delivery.


3. Services


Really the WCF is made up of 'Services' and 'End points' that communicate with clients. The Services are hence composed of:


A) Service Description: How to access this service and what functionality this service provides.


B) End Points: Each Service must have at least one End Point and further each End Point must have a unique Address e.g. "http://MyService/MyFunctionality..."


Each End Point is composed of a Binding, Contract and Implementation. Binding refers to http, basic http, WShttp, Nettcp etc. Contract is a definition of actions for this end point.


Contracts


The Structure and format of a WCF message and the behaviour of the Message is called a contract. It is in the shape of a well formed xml document like WSDL. Several kinds of Contracts:


A) Service Contract: Tells the Clients of the service, what operations this service will perform, the message data types and where this service is located.


B) Message Contract: Allows customization of the format/structure of the message sent and received by WCF. Also allows formatting the parameters of the message.


C) Data Contract: This is the data being exchanged between Client and the server. The two need to agree upon the format for the data exchange to take place. XML Serialization facilitates this exchange; however there is a new serialization in WCF called Data Contract Serialization.


4. Behaviours


The Service Behaviour basically controls the runtime behaviour of the service and/or the End Point. For e.g.:


--> Throttling - No: of threads per process, Concurrency Processing.


--> Security


-->Instancing - Per call, Per session, Single.


--> Transactions etc.



Hope you enjoyed the heaavy reading. Till next post signing off...


PV