Understand Service-oriented Architecture

Service-oriented architecture, or SOA, is an extraordinary step in the application architecture evolution.  In order to solve the problems with today’s component-base architectures, we need to architect systems that expose business logic in a well defined way, adhere to industry standards, and do not require any specific implementation or technology by the calling application.


In other words, we need a mechanism to wrap the business objects and provide a well defined access point for calling applications.    

A service-oriented architecture is layered just like the component-oriented architecture.  It consists of a data access layer and a business layer.  The presentation layer exists, but is not part of the service-oriented definition.Additionally, a service-oriented architecture contains a well defined service interface.  This is the access point for all external calling applications.  Each method on the service interface has a single, well-defined input parameter and a return type.  The service interface method supports a request/response metaphor. The service interface is responsible for controlling access to the business layer.  Any applications or other services calling the service interface do not have access to the business layer.  This provides a loosely coupled architecture – the service’s implementation can be changed without requiring any changes on the calling application.

A service-oriented architecture solves the following problems:
  The service can be deployed to any type of machine.
  The service can physically reside anywhere on the network
  The service can be developed in any language.

Definition of a Service
We have defined what a service-oriented architecture is, but what exactly is a service within a service-oriented architecture?

A service can be defined as a software system that:
  Corresponds to a real-life business activity ( placeOrder or submitClaim )
  Is the interface for a business function or functions
  Is usually discoverable, but not always
  Has a well-defined interface, which is exposed through some sort of contract
  Interacts with other services and components using loosely coupled, message based architecture and asynchronous or synchronous access models
  Uses industry standards for communications
  Provide interoperability
  Is up and running all of the time, versus a component that must be instantiated
Benefits of a Service-Oriented ArchitectureApplications are complex to design and build.  Businesses need software to be agile and flexible to ever changing business requirements.  Businesses need software to interoperate with other businesses software.

Today’s component-based architectures cannot provide this flexibility and interoperability.  Service-oriented architectures, on the other do, provide a flexible and interoperable solution for the agile business.

Service-oriented architectures provide additional benefits by:
  Encapsulating complexity – systems are hard to build and very complex.  SOA provides the mechanisms to hide the complexity and provide a simple well-defined interface to the business logic.
  Providing location independent code – the service can be located anywhere on the network on any machine.  Additionally, the service can be written in any programming language.  The client does not need to know how the service was implemented and what language was used.
  Allowing developer to focus on specific issues – service developers will be concerned with things like transactions and messaging.  The client developer only needs to know how to invoke the service.
  Allowing parallel development – once a service interface is defined, the service can be implemented in parallel with the client application.
  Providing support for multiple client types – different types of clients can access a service.  As long as the client is network aware, it can invoke the service.  Clients can be web-based, windows-based, console-based, or pda-based type of applications.
  Providing a standard place for implementing security
  Increasing re-usability


Check yourself whether you are a professional programmer – UI Process Application Block

Last week Sunday while I was conducting a SharePoint WorkShop to my group members,before deeply getting into the agenda I just simply asked how many of you guys worked with UIP and shockingly everybody said  ‘no’. I really got wondered and just realised that the software vendors are the culprit whom neither has a standard to follow or an architecture and just simply working on the projects just for revenue earning purpose.

This really made me to think a lot first of all in my experience every  organization should have experienced developers as OO centric and apply UIP suppose even the system is complex , then UI process block is a must have framework as well.

Below is the article to give you an better idea about UIP if you haven’t heard about earlier.

Most UI development is dependent on pages/ screens communicating with each other. Historically there have been two approaches to UI design. Model View Controller  ( also known sometimes as model 2) and the more simplistic model where every UI page/ screen knows about every other screen.This is also known as Model One architecture.

MVC UI architecture provides a clean separation of UI logic from the business code by providing a layer of separation between the two. This makes code maintainable and reusable.

Languages like Java have adopted this approach with frameworks like Struts and Web Work. ASP.NET by default is based on a the concept of a controller for every page in the form of a code behind where all the event handling occurs. However every page in this structure knows about every other page that it has to communicate to.

This lends to lots of code in the code behind class that  does not easily lend to reuse. Another drawback is in testing the code behind. Since the code behind requires a container to run in, it becomes increasingly difficult to test the logic that goes in these classes.

UI Process Application block from Microsoft is an API that is written for large applications that have complex interactions.The process block does not assume a web based system. It can be used for rich clients and can be easily be extended for other custom clients

This application block provides session management, task management, state management and navigation management among other features. 

This article explains techniques for testing code using UIP and other practical suggestions that will allow for understanding the application clock better. This article is focused around developing web based systems. However some of the concepts may very well  be applied to other kinds of systems.

Using UIP 2.0

The main parts of the UIP block are the View and the Controller. Every page is a sub class of WebFormView. Views talk to the backend using controller. Views know only about themselves. Controllers in the application blocks are basically commands. Every view interacts with a controller.

Views are routed based on a navigation graph. Think of this as the sequence of steps or pages the user is required to go through. Here is an example of an entry in the config file


  <view name=”MyHome” type=”home.aspx” controller=”MyController” />


A page called MyHome is part of a NavigationGraph called MyController  which is defined in the config file as a WebFormViewManager.

Home.aspx.vb  is a subclass of WebFormView,  MyController is a sub class of ControllerBase.

As shown in the sequence diagram above  the controller processes the users request, thus removing the call to the backend away from the code behind to a controller class.Note how a given web page is not aware of other pages. This separation is achieved by defined all the routing information in the config file

Navigation Management – Using GraphNavigator  for a web based system

The UIProcess block works by trigerring a  navigation path using  a navigator. One such navigator is the graph navigator. Graph navigator forces the user to follow through a sequence of steps or a workflow. This feature is very useful for a system that requires such a workflow. There is the ability to disable the back button in such a way that the user will always be forced to go to the current state in the graph.

This limits the users ability to freely move around the system, which is required of many portals like news sites, health information sites( Non transactional / Non workflow based systems) . The open navigator ( instead of the graph navigator ) allows the users the ability to jump from any node in the navigation path to any other node.

Typically every application is taken to a home page when the application starts. To kick off navigation, somewhere in the beginning of the session ( like the global.asax file) the start navigation path can be initialized.   The important thing to realize is that not  every page in the system has to be in the control of the UI Process application block.

Pages that do not have to follow a certain graph don’t have to under the control of UIP. The problem is that things like task objects that hold on to state information will then have to be passed to such independent pages in other ways.

Here is an example  that demonstrates this.

Let’s assume that  a system has four pages. PageANotUnderUIPControl,PageBUnderUIPControl, PageCUnderUIPControl,PageDNotUnderUIPControl.  The user starts at A and can navigate to B and then based on a user selection can go to either C or D as shown below.

PageA will basically route the user by doing the following line of code

 – UIProcess.StartNavigationPath(“{The name of the path For B}”)

B-  user does something that needs to be stored for the

next screen C to use.

In B we call

MyController.SomeMethod( passTheData )

and in the controller we can store in the State as MyController.State(anObject, passTheData)

State is a sub class of DictionaryBase, an abstract class that allows for strongly typed key and value pairs in its sub classes. Using the state is how caching is done in a given navigation path. This is different from the System.Web.Cache where is Key cannot be any object than a string.

Now if page B passes the call to a page D, there is no way of getting to the information in the State cache as this is outside the navigation graph. This results in duplicate cache maintained in  a session.

If a user is in a particular screen in a browser he/ she can typically open a new browser instance from the same session . UI block keeps track of the various browser instances in a session and controls user entries.

On many we transactional web applications the user can click the back button and cause issues like re submit the data on the screen. Setting the allowBackButton to false in the config file would force the user to stay to go to the next valid state .

Unit testing with UI Process application block

Testing the code in the UI layer can get quite complicated. When using UIP, the view classes  in a web system extend    WebFormView. Such view classes are dependent on the need for running inside a ASP.NET container. But NUnit runs outside and does not have access to the the

Classes that subclass ControllerBase have code like

Me.State.NavigateValue = "fail"

When writing a unit test, the code above will fail as there will be no place to navigate to when a NUnit test is running.

Controller can delegate its calls to smaller logical command classes. Those smaller classes can then be tested independently by NUnit,

Consider the method AddToCart  that is a method on a controller class. It is tough to test this method  using NUnit. This is because NUnit would not no what to do when Navigate is called . ( Navigate takes the user to the next aspx page)

Public Overridable Sub AddToCart(productId As Integer, quantity As


   Dim cart As New CartBusinessObject()= businessComponent.GetCart(user)            

   if cart.Validate()


      cart.AddToCart(Cart.CartItems, productId, quantity) 


   End If

   Me.State.NavigateValue = “addItem”


End Sub ‘AddToCart

To overcome such issues the logic of validating and saving can be moved to a command object . Class AddProduct  has a method called execute that takes the necesarry parameters for that command to succeed

Public Class AddProduct

      Inherits ICommand

Public Sub New (user as User, productId As Integer, quantity As Integer)      

‘Initialize here – Not shown

End Sub ‘New

Public Sub Execute()

Dim cart As New CartBusinessObject()= businessComponent.GetCart(user)            

  if cart.Validate()
     cart.AddToCart(Cart.CartItems, productId, quantity) 
  End If  

End Sub

End Class ‘AddProduct’   

This is a class that can easily be tested using NUnit . Now the controller looks as shown below

Public Overridable Sub AddToCart(productId As Integer, quantity As

    Me.State.NavigateValue = "addItem"
 End Sub 'AddToCart
 The only thing that cannot be tested is the navigation which is certain to be tested developing the UI.

ASP.NET Futures Released

Yet another release from Microsoft to make programmers life simple ,click here to download

The Microsoft ASP.NET Futures July 2007 (“Futures”) release contains an early developer preview of features providing a wide range of new functionality for both ASP.NET and Silverlight™. The functionality in the Futures release includes early experimental versions of features currently being considered for future versions of ASP.NET and the .NET Framework. The Futures releases assume prior knowledge of the core features of ASP.NET including the previous ASP.NET AJAX Futures January CTP.Features in this release include the following:

  • ASP.NET Silverlight server controls.
  • New functionality for ASP.NET AJAX Extensions.
  • Dynamic data controls, which enable rapid Web application development when you work with Microsoft SQL Server databases.
  • Enhancements to dynamic languages, including IronPython and Managed JScript.

Enjoy Programming , Microsoft is a real Giant.

Final Version of SilverLight Released on Sept 5th 2007


Exciting news ,awesome technology and tools from Microsoft to bring wonderful UI and provide mind blowing controls for our application development which is really going to create a big revolutionary across the customers. 

 Microsoft Silverlight is a cross-browser, cross-platform plugin for delivering the next generation of .NET based media experiences and rich interactive applications for the Web. Silverlight offers a flexible programming model that supports JavaScript, .NET, and other languages.

Already 1000 companies in the world are experiencing the applications developed using silverlight beta. So adopt yourself  to silverlight before your company customers comes to you.

Visual Studio.NET 2008 and Expression Studio are also released to design and develop Silverlight applications.

 As a first step, check out the Getting Started with Silverlight Video.

To get started with Silverlight, download Silverlight 1.0 if you are using JavaScript or the 1.1 Alpha refresh to use .NET languages. For more information on the features in 1.0 and 1.1 see the features matrix.
Microsoft Silverlight 1.0 – Mac or Windows
The runtime required to experience Silverlight.
Microsoft Silverlight 1.1 Alpha September Refresh – Mac or Windows
The runtime required to view Silverlight applications created with .NET
Microsoft ASP.NET Futures (July 2007)
This release includes Silverlight controls for ASP.NET
Then download the Visual Studio developer tools to start developing Silverlight applications, and the Expression designer tools to start designing Silverlight application. For additional information on the tools read the overview.

Developer Tools
Microsoft Visual Studio 2008 Beta 2
The next generation development tool.
Microsoft Silverlight Tools Alpha Refresh for Visual Studio (July 2007)
The add-on to create Silverlight applications using .NET

Designer Tools
Expression Blend 2 August Preview
Professional design tool to create user interaction for Silverlight.
Expression Encoder
Feature that will be part of Microsoft Expression Media that allows you to create and enhance video.
Expression Design
A professional illustration and graphic design tool to create Silverlight assets.
For documentation, samples and add-ins, also download the SDK’s.
Software Development Kit
Microsoft Silverlight 1.0 Software Development Kit
Download this SDK to create Silverlight Web experiences that target Silverlight 1.0. The SDK contains documentation, samples along with templates for Visual Studio.
Microsoft Silverlight 1.1 Software Development Kit Alpha September Refresh
Download this SDK to create Silverlight Web experiences that target the Silverlight 1.1 Alpha September Refresh. The SDK contains documentation and samples.

Windows Communication Foundation -Simple Program

Based on my previous WCF post I received a trackback to give an example that should be really simple to start WCF with.

There are two ways to present this. In this example I’ll use as little code as possible in as few locations as possible. The other way is using the WCF Service Library project that comes with the VS2005 WCF Extension but requires a lot more code, text, etc.

I’m using two projects, because WCF is all about getting clients to communicate with a service. Let’s start.

1. Open Visual Studio 2005 and create a new console application project, called “CalcServiceHost”.

2. Add a reference to the project for the System.ServiceModel assembly. It’s the core assembly used by WCF.

3. Add a using statement at the top of your class for System.ServiceModel.
using System.ServiceModel;

4. Create a service contract and implement it in the Program.cs file, directly under your Program class. In this example I’m expecting a two numbers and adding this and return the output.

class CalcService
  int Sum(int first,int second)
    return first+second;
5. In your Program class, inside the static Main method we need code to host our service. We’ll add two endpoints, one for our service and one for extracting the metadata.

 1 static void Main(string[] args)
    2 {
    3   // We did not separate contract from implementation.
    4   // Therefor service and contract are the same in this example.

5   Type serviceType = typeof(CalcService);
    7   ServiceHost host = new ServiceHost(serviceType, new Uri[] { new Uri(“http://localhost:8080/“) } );

 9   // Add behavior for our MEX endpoint
   10   ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
   11   behavior.HttpGetEnabled = true;
   12   host.Description.Behaviors.Add(behavior);

 14   // Create basicHttpBinding endpoint at http://localhost:8080/CalcService/
   15   host.AddServiceEndpoint(serviceType, new BasicHttpBinding(), ” CalcService “);

 16   // Add MEX endpoint at http://localhost:8080/MEX/
   17   host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), “MEX”);
   19   host.Open();
   21   Console.WriteLine(“Service is open, press any key to close.”);
   22   Console.ReadKey();
   23 }

At line 7 we’re instantiating our ServiceHost object, specifying a base address at localhost on port 8080.

At line 15 we’re adding our endpoint, using basicHttp, for our service.

At line 17 we’re adding our metadata endpoint. For this we also need to specifiy the MetadataExchange behavior, which we do at line 10, adding it to our ServiceHost at line

12. At line 11 we’re enabling HttpGet, which means we can view the metadata using a browser.

At line 19 we just open the host and everything should work fine. Lines 21 and 22 are waiting on confirmation of a user to close the console application, automatically closing our ServiceHost and thus our service.

We only need to ad a using statement for the System.ServiceModel.Description because adding a MEX endpoint using code requires this namespace.
using System.ServiceModel.Description;

6. Now this is done, let’s try and run our service. If all goes well, we’ll see the message that the service is ready. You can check it by opening up a browser and visiting http://localhost:8080/

7. Now we need to create our client. Add a new Windows Forms project called “CalcServiceClient” to our solution.

8. Right-click the “Host” project and choose “Debug” and then “Start New Instance”. Then right-click the “CalcServiceClient” project and select “Add Service Reference”. In the dialog that appears type in the address http://localhost:8080/ and press “OK”. Now you should have a new folder in your “CalcServiceClient” project with the reference to your service. Stop the service that’s still running in the background.
The System.ServiceModel assembly should be referenced now, the app.config has been added and modified as well as a proxy class under your “localhost” service reference.

9. On your form in the “CalcServiceClient” project, add a textbox and a button. Double-click the button.

10. Add three lines to your button-click event.

1 private void button1_Click(object sender, EventArgs e)
    2 {
    3   localhost. CalcServiceClient proxy = new Client.localhost. CalcServiceClient();
    4   int sumResult = proxy.Sum(textBox1.Text,textBox2.Text);
    6   MessageBox.Show(sumResult.ToString());
    7 }

11. Again, right-click the “CalcServiceHost” project and select to start a new instance and do the same for your Windows application. Then fill in the two numbers in the textboxes and press the button.