Monday, April 13, 2009

MVC - Model View Controller

Recently while working on a Project I came across Navitaire Flight booking system and realised they used a fairly interwoven system of MVC and a WCF services layer.

Here are my 2 cents worth on MVC pattern.

MVC is an architectural pattern used in software engineeering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other.



MVC Pattern
The whole Navitaire application is based on the MVC or Model View Controller Pattern; also known as MVP or Model View Presenter design pattern.

Model
The Model is responsible for managing application data and state, and communicating with a server. When an operation is performed on a model that changes the data or state of an application, the model notifies all of its consumers.

View
The View represents the presentation layer of an application. A view does not necessarily refer to a Windows form or a Web page and may not be visual at all. For example, a Web service or voice interface can be different views of the application that present the application data to the user.

Controller
The Controller provides validation, security enforcement and application workflow logic. For each user operation defined in an application there should be a controller method that is invoked that validates the data and security before invoking method calls on a model object. Logic related to application workflow can also be contained in the controller and may be dependent upon the active view.

As usual don't forget to leave comments. Thanks.

Wednesday, April 8, 2009

How To Program WCF

There is so much to understand and so many classes for WCF, but fortunately programming for WCF is streamlined.

1. Object Oriented vs Service Oriented
Before we get into some programming syntax, let us look at what will be different for us as traditional OO (Object Oriented) programmers to get into the SO (Service Oriented) mode.

Object Oriented - Classes and Interfaces are the norm. Two Libraries dependent on each other communicating via dstributed object calls. Hence OO is a tightly coupled way to develop applications.

Service Oriented - Classes and Interfaces are still in use but there is decoration of WCF classes by attributes like ServiceContract, OperationContract. Since the application components and services are connected via messaging mechanism (passing messages) across different platforms, it is called loosely coupled.

e.g. A School Service:

[ServiceContract]
SchoolService
{
[OperationContract]
double CalculateStudentFee()
{
...
}
}

2. Understanding Service Model in WCF


Most of the functionality is provided by System.ServiceModel Namespace. A WCF Service Provides functionality/operations to other services or applications and consists of one or more End Points. Each End Point, in turn, consists of Address, Bindings and Contracts.


Address --> Where the service resides.

Binding --> How the service communicates, Protocols etc.

Contracts --> What the Service does, What it provides.


e.g. of System.ServiceModel Classes

NetTcpBinding, BasicHttpBinding, ChannelFactory, Identity (For Identification as messages are exchanged between End Points), ServiceHost (To Provide a Host).


e.g. of System.ServiceModel.Channels

These classes are used in communication between EndPoints. Some of the examples are as follows:

AddressHeader, MessageHeader, Binding (Collection of BindingElements used for specifying communications for each End Point), BindingElement, BindingContext.


Transactions

As with any other context, ACID Properties define a transaction i.e. Atomicity, Consistency, Isolation and Durability. There is a Namespace called System.Transactions which has couple of classes in it:

--> Lightweight Transaction Manager (LM)

--> OLETx Transaction Manager


As a final note, WCF allows passing transactions from Client to server.

Lets look at a code example and some explanation to understand the basic constructs of WCF programming:


[CODE EXAMPLE]


3. svcutil.exe


This is a utiltiy which will be used a fair bit in our strides into WCF programming. This generates service code from metadata docs and metadata from service code. Many switches/options for metadata generation, code generation and serialization etc. are available. In general svcutil syntax is as follows:


svcutil [options][metadatapath|assemblypath|metadataurl]


4. WCF Programming Methods


There are several ways to do WCF Programming. One or a combination of them could be used. In the next series of articles, Let's have a look at them one by one.


Sunday, April 5, 2009

Blog Away

After almost a year of hibernation,I decide to venture back into blog arena and sure enough instead of concentrating on real purpose of my blog, I went into 'Make Blog Popular' Mode...

Increase your Blog Views - Register with Technorati
Increase even more - Register With Blog explosion
Blog views Stats - StarCounter
Monetize - Google adsense (Dont click on it yourself mate ;)

Anyway I am guilty of Blog philia this weekend. I will be back to my usual ramblings soon. Reading a book on WCF by Michelle Bustamante and some MS Architecture guidelines.

Catch you later.