Tag Archives: Services Oriented Architecture

Using Windows Communication Foundation WCF with Visual Studio 2008:

There is a lot of hype about new (not so new now) technologies from Microsoft and the new architectures that are now a part of Microsoft .Net development environment. These include Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF) and Workflow Foundation (WF).

I will give a brief introduction about what these are just in case you are not familiar. Anyways if you are then probably this article is no good J since I just started working with these. This will help you get a quick start in case you are a starter and I have gathered the info skimming through tutorials and I want to give you something quick and easy. So to start off “What is WPF?” WPF exclusively has everything to do with the UI or user interfaces. Till .Net 2005 the Graphics were GDI (Graphics device Interface) based and in WPF they are Direct X based thus utilizing the faster video card acceleration and fast memory access as compared to the GDI. Secondly this used to be an issue when clients wanted fancy UI e.g. Elliptical buttons, Window Layouts, Animated menus and colors in controls. Microsoft made it possible with user controls to some extent but off course the mainstream developers didn’t want to get in that mess and always wanted to use the default controls with some styling that the client wont like. Customers these days doesn’t want “just another windows button” there should be something innovative about it so WPF enables you to define your own controls with XAML pronounced as (zammel).

The styles, colors, shapes, data bindings and everything that is a part of the control can be done using XAML which is simple xml just defined somewhat like html ( I always see the elements and attributes notations) whenever I see XAML.

So WPF is for UIs and probably an effective solution for at least Windows Vista if not XP. Just as with the “User Interfaces” Microsoft realized that “Services Oriented Architectures” are gaining in popularity. With Central server centric applications and Microsoft efforts to support the SOA with applications like “BizTalk”, “SharePoint” e.t.c something also needed to be done to provide a standard platform for network programming using .Net. Microsoft came with WCF which is a powerful framework for writing and utilizing or consuming web services , windows services , .Net Remoting without needing to write a whole lot of socket interfaces. The implementation is hidden in the components constituting the WCF. WCF like WPF depends heavily on configurations and it is usually a good idea to separate the business logic from the configurations or the (app.config) file. In this article I will demonstrate writing a simple client server program using WCF which will give you some bare essentials for WCF and will help you to explore more in the ever growing world of emerging technologies.

By the way just to get you started if you are not familiar with the client server paradigm, client server application that I am going to develop would be basically two applications. A Server application will let many clients connect to it and say “Hi”. Keeping in mind this is not to tell you how to design better client server applications this is all about getting you up and running with WCF. Ok my friends so don’t get angry =] 

Designing the Client and Server with WCF:

Primarily while designing the application remembers there should be something common in the client and server. To explain this better ask yourself the question “How is client going to interact with the Server”? There should be some interface the server should provide to achieve this. If you are familiar with web services think of wsdl (web services description language) that exposes the web service API. So just like that the WCF Service also exposes interfaces. The clients can generate the proxy classes for the API and will call those API methods to communicate with the Server with underlying implementation of Sockets and communication mechanism). I will discuss “How to generate the proxy classes” but first things first “Decide what should the Server be like”? And “what functionality you want to expose”?

So just for the sake of simplicity just think that what the server wants to expose and client wants to consume is 1 single functionality called send message.

 

The First Step in Writing the Server: 

I consider adding the “system.servicemodel” reference a prerequisite to every WCF application so if you have not already added that do make sure the reference is included in the list of your references.

1/ Add a new interface to your solution. I named the solution as WCFServer so the namespace here is WCFServer. I named the interface as CommonInterface just to be clear what this does. This would be the API exposed for the client and would be executed on the server. Good naming convention for this would be to prefix the name of the class with an “I” so something like ICommonInterface but that’s something you know right.

namespace WCFServer

{

    [ServiceContract]

    public interface CommonInterface

    {

        [OperationContract]

        void SendMessage(string msg);

 

    }

}

Observe that there are two things here which might be new to you. The interface is marked as “ServiceContract” which is the attribute which specifies that this is the contract between the client and server.The other thing is the method is marked as “OperationContract”. For the time being just think that every method in this interface should be marked as an “OperationContract”. This method is what will be executed on the server and what the client will call from the “Client code”. 

Second Step is to implement the Interface with your server class:

Give a meaning to the interface by implementing it in your server side code.How to do that is declare a class in your program and name it appropriately and inherit it from this interface that we defined in step 1. For our sample application I defined the server class as shown in the definition below:

 

namespace WCFServer

{

    class Server : CommonInterface

    {

        public void SendMessage(string msg)

        {

            Console.WriteLine(“Message from client –> “ + msg);

        }

 

        static void Main(string[] args)

        {

            Console.WriteLine(“Starting the server …”);

            ServiceHost host = new ServiceHost(typeof(Server));           

            host.Open(); 

            Console.WriteLine(“Server started successfully at…Pressing a key would cause the server to shut down …”);

            Console.ReadLine();

            host.Close();

        }

    }

}

 

So if you look at the code closely you will find the implementation of the “SendMessage” function that will be called by the client and a message would be passed and displayed on the Server’s console window.

If you look at the Main function the first thing that we do is to declare a Service Host and specify the sever’s type. Then use the Open method of the service host to start the service.

Our server at this point is up and running and waiting for the clients to say “Hi”. How to write the clients will be discussed in the next article. Hope this helps getting you a quick start of essentially what it is and if you have any ideas, observations I would love to hear from you in the form of comments.Stay tuned for more and thanks for reading.Happy Coding !!

Here are the Configurations necessary for the configurations: 

<?xml version=1.0 encoding=utf-8?>

<configuration>

  <system.serviceModel>

    <services>

      <service name=WCFServer.Server>

        <endpoint address=net.tcp://localhost:5555/Server binding=netTcpBinding

            bindingConfiguration=“” contract=WCFServer.CommonInterface />

      </service>

    </services>

  </system.serviceModel>

</configuration>

 You can use the “svcconfigeditor.exe” to generate this so you don’t have to memorize this simply go through a wizard and save the file as app.config and copy and paste.The svccinfigeditor can be found at “C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

 

1 Comment

Filed under C#

Concept of Services Oriented Architecture

There are many different styles of applications that are written today. But lately we have seen a paradigm shift where the concept of “Software as a Service” is really been taken seriously. If you are an IT professional chances are 9 times out of 10 you must have heard of the term “Services Oriented Architecture”. What the heck? And you are like “Yeah, I know what that is and you go on  You make an application that consumes a web service!! Bingo!! ” No that’s not what SOA means’s is a new software development model or “An architectural style” where the business layer instead of integrated in the code is rather orchestrated :S . Confused already??  What I have realized over a period of time in the Software Market, whenever a new technology comes don’t jump into that technology and just know the couple POWER Words to horrify your bosses. I bet you 10 to 1 that Mr. John Doe or whatever!! Standing by the coffee machine and boosting about that “New technology” knows little about it.The key idea is to write software as a service ( It may be a web service or a windows service , a service within the enterprise accessible to you from your browser or a service that is published on the internet with a valid WSDL).If you notice the companies that have made it really big during the past year e.g. Google , Amazon and EBay I think the primary reason of their success lies with adopting the new software development paradigms and quickly able to deliver business rules with their service orientation.

So ok!! You want to know what exactly a Services oriented Architecture is. It’s a new software development paradigm which is suitable for applications with distributed processing capabilities .How it helps business?

 Information technology is the backbone of nearly all major businesses. Nearly all major businesses today are Information technology driven. Any change in the business rules or business process (ways in which business is conducted) implies a change in the legacy system infrastructure. This change is sometimes difficult to implement as business logic or business rules are implemented as software code. The legacy systems lack the interfaces and are not designed to integrate / interpolate with newer systems, thus the company looses profitable business and a huge factor is the extent to which the legacy systems can be made scalable. We need a new paradigm of Agile Software development where we need to extract the business logic from the actual implementation and expose the data to other applications for quick integration. The idea is to design software architecture around a set of services which are loosely coupled, scalable, reusable and easily integrated. The architecture is called “Services Oriented Architecture” where software can be implemented as a set of loosely coupled and highly cohesive services that may be used by a number of internal / external applications.However, with its advantages there are upfront development costs (time and money) associated with changing the architecture of the software infrastructure and it depends on the nature of the business, the role of IT in the business and the different costs that are required to change the legacy systems whether the company want to adopt the new applications paradigm or not. With that said, it does provide lots of incentives once implemented properly including higher integration options, existence of business process as configurations, higher reusability, a higher degree of compliance with standards ,  increased cohesion within the sub system and decreased dependencies between subsystems Common misunderstandings:Certain level of misinterpretations and misconceptions about Service Oriented Architecture prevail .The primary misconception of this software architecture building methodology is due to a key technology the Web services. The service oriented architecture and the applications that follow SOA are often confused with just the Web services. Some of the common misconceptions are listed below: 

Any application that uses Web services follows a Service Oriented Architecture.

An application that uses a Web service might follow a Service Oriented Architecture or it might not. It depends on the application’s own design, architecture and design considerations that determine its architecture.

 SOA is same a re – branding Web services:Many people think that Services Oriented Architecture is nothing more than a marketing term which might be interchanged with Web services. The important concept they are missing over here is SOA is another Software Architecture that results in the functionality being distributed to many independent Services to better process Business processes.

 Adopting a Services Oriented Architecture Ensures everything can interoperate:It is not necessary that any application that is developed as per the SOA artifacts would be able to interoperate or integrate necessarily with any other component / application or legacy systems. However SOA gives a high emphasis to increase the degree to interoperability by standardizing the Services produced using SOA. 

If you can use a web service with your application you can easily develop applications based on SOA. SOA is the same as distributed computing with Web services. Pitfalls: If there were no potential hazards, problems and everything was ideal with implementing SOA perhaps all the enterprise software today would have been based on Services Oriented Architecture. It depends on the type of functionality, nature of components, exposed interfaces, degree of reusability and working of an application that determines it architecture. Some of the common pitfalls are mentioned below:

 Designing and implementing an application like traditional distributed architectures:SOA is a relatively newer agile application development paradigm. Many of the new Services that implement SOA are designed just like a legacy application that followed a distributed architecture. This would involve Remote Procedure Calls, non standardized definition of services and an improper definition of the function boundary resulting in an increased degree of dependency and lowering the functionality contained in the Service. 

Not making XML the foundation of application architecture:This also has something to do partly with standardization. All applications that follow SOA should conform to certain standards, the foundation of which is XML.Contemporary SOA cannot be achieved if the internal and external interfaces of the Service don’t use XML as a basis. e.g. A key enabling technology in the Services Oriented Architecture are the Web services. Web services are described using a WSDL (Web Services Description Language) which is XML based. Other than that the BPEL (Business Process Execution Language) and some other key components are also XML based. 

 Ignoring the Performance Requirements of a Service:Usually due to the communications overhead performance of applications or Services following contemporary SOA can be below the required level of performance. The message processing time for the service should be reduced by optimizing the code , reducing the number of request / response and it should be made sure that the Service meets the required response times and performance criteria. This can be done by extensive testing (Stress testing) for various input / output conditions. Not making the services secure:

SOA is most likely to be used as architecture for distributed applications. SSL (Secure Socket Layers) is not the security consideration here. The application designers should also consider the WS-Extensions and security frameworks provided by other vendors in order to provide a standardized software design that follows SOA principles.

Now you would ask hey hey hey!! Wait a second: S!! How BPEL, ESB, grid computing and the Business Intelligence do fits in? What the heck are these J I would be happy to explain if you have that in mind.For now just like John Doe who is standing by the coke machine hehehehe understands that BPEL is the Business Process Execution Language, ESB is the Enterprise Service bus and Grid Computing hmmm has many concepts for virtualization? Technically speaking these all are layers of the Architecture we discussed about called SOA and how these are written , mainly in XML yes business rules with xml is BPEL. ESB is where the services are available on one on many services. It can be taken as the medium where the services reside on the www. If you have any questions / suggestions / queries / ideas in your mind do post your comments. Thanks Note: I have taken the concepts of these pitfalls and disadvantages from a book on Services Oriented Architecture(Concept Technology and Design)  by Thomas Erl

Leave a comment

Filed under Software Design