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


Friday, July 20, 2007

SOA and WCF - Introduction

Hi SOA people,

I have been reading up on SOA using various resources and I thought I will start with this introduction.

Long time ago
Long time ago there were COM+ applications, MSMQ - the reliable applications. Then there were asmx, WSE ones - the cross platform, soap based communications across networks. And of course Remoting - object communication between applications anywhere on your network. We have worked with these technologies leveraging them as clients i.e. calling other services or as sevices who service clients. More on this service, client bit as we move along. Of course now we have WCF, which is perhaps more native communications i.e. at a message level.

SOA Priniciples
What basically defines or qualifies as a service? It needs to satisfy some principles.
A) Explicit bondaries: The Servicc emust be able to cross explicit/formal applicationa nd network boundaries.
B) Autonomous: Changes in one service in a distributed scenario should not affect other services i.e. each Service has a self containing and a self describing functionality.
C) Policy: Policy Expressions are machine readable stuff which assist in checking out the communication info and basically is checked out by other services trying to communivcate with our service.
D) Schemas and Contracts: These are basically data and Behaviour respectively. Services pass around contracts - the message structure; they don't pass classes and types.

That's great we are doing good. But hang on, we know at a high level what SOA is all about; where does WCF fit in?

WCF - What's it all about?
WCF is nothing more than a Framework sitting on top of .NET 2.o runtime allowing creation of distributed, loosely coupled service oriented applications which are reliable, secure and transaction capable.

WCF Features - Only some of them here!
  1. Interoperability - Operating system, platforms and environment interoperability is all cool for WCF. One WCF Service will happily work with number of platforms and OSs.
  2. Hosting - Windows Activation Services, NT Services, Win Forms, IIS, Console Apps are some of the hosting options. Is that cool or is that cool?
  3. Security
  4. Queuing - leveraging MSMQ transport.
  5. Transactions.

WCF Components - what is it intrinsically i.e.what is behind this box WCF?

  1. Contracts - refer to structure of the message and is of several types: Data - this refers to the return types and the parameters, Message - Format of the Message parameters, Service - Description of data types, Policy - Security, Protocol and how to communicate with a service.
  2. Service Runtime - This refers to the behaviour of the service during runtime or service operation. Some examples are 'Throttling' - No: of processed messages, 'Transactions' etc etc.
  3. Messaging - Refers to Message format and data exchange patterns during service communication. It also refers to Channels like WS channel, MSMQ Channel, HTTP, TCP etc.
  4. Activation and Hosting - These are the options where the service can be started and hosted. e.g. Windows Activation Service (WCF Services can be auto started if WAS is on the computer), as an exe, Windows Service and s a COM+ application.

That's all for this blog entry but more will come on the ins and outs of WCF before we turn to actually addressing each component of WCF in detail like Channels, Services etc.

Cheers.

Thursday, July 12, 2007

Purpose

Hi There,

Every blog needs a purpose and this one sure has one! All About Software messaging and communications - you know what I am talking about asmx, WSE2.0, WSE 3.0, MTOM and now WCF. Yup it is for programmers, but you may find some technical docos on and off which are conceptual in nature.

Happy posting and feedback - the good, the bad and the ugly, always welcome.

Cheers.