Sadek Drobi’s Blog

November 22, 2006

OBSEV :: SOA and Orchestration with .net 3.0’s WCF / WF

Filed under: Architecture, SOA, WCF, WF — Sadache @ 3:50 pm

I promised Demos for the .net 3.0, and here is my first and simplest J

Talking SOA, there are several important principles about it, one of them ORCHESTRATION.

Business Logic is never Logical (martin fowler) , so it could be a good idea to externalize this “logic” and make it so easy to do composing services from lower layers in the application architecture, this way, you offer your client an easy tool, to compose reusable services to form the needed business process.

That what Orchestration is somehow about, one important standard implementation is BPEL, an XML representation of the services composition, and thats were my demo starts.

.NET 3.0 delivers a very easy SOA platform, Windows Communication Foundation (WCF), that really helps with interoperability , uses AOP so it is quite easy to add behaviors to the offered service, through configuration file, Transactions, Security , Compression …etc , will be translated into soap headers, confirmed to standards, I pretty happy about this platform  .But I still need human Orchestration tool, and here it comes .net 3.0 with its Windows Workflow Foundation (WF), I am really amazed with how easy to use this tool is, I strongly urge you to replace your workflow , or orchestration tool with it.My demo that follows illustrates a very simple application, that has two services (WCF), that are composed with WF into a third Service , that is published through asmx webservice J

[ServiceContract()]   

public interface ICalculator     {

        [OperationContract]

        int Sum(int par1,int par2);

}

[ServiceContract()]

public interface IBenefitCalculator{

         [OperationContract]

         float CalculateRatio(int par);        }public class Calculator : ICalculator    {        public int Sum(int par1,int par2)

         {            return par1+par2;

        }

 }

    public class BenefitCalculator : IBenefitCalculator    {

         public float CalculateRatio(int par)

        {            return par*10/100;

        }

 }

One of the main conceptions behind WCF is the separation between code (that is for programmers) and configuration of behavior (that is for administrators)Here all what I did is create two interfaces m and implemented them, all what I had to do in this dll library is add the attribute [ServiceContract()] for the interface and  [OperationContract] for the exposed signature.I did another project which is the host for my WCF services, quite simple, a web form that has two buttons, for starting services and stopping them.Code for doing this is quite straightforward internal static ServiceHost myCalculatorServiceHost = null;         internal static void StartCalculatorService()         {            Uri baseAddress = new Uri(“http://localhost:8080/calculator”);            myCalculatorServiceHost = new ServiceHost(typeof(WCFCalculators.Calculator), baseAddress);            myCalculatorServiceHost.Open();        }It would be better to keep the service address in the config file, so think about doing it.That’s all about code, now we have to define the End Points ABC (Address is already defined in the code, so we still have to define Binding and Contract)I used basic basic http binding, changing it to secured doesn’t really need a lot to do, just a small configuration change, Here is the binding I usedNow as I have my services ready, my host as well, I go for orchestration, that was the simplest part, I just added a new workflow library, I added WebServiceInputActivity/ WebServiceInputActivity which says that the input to my workflow will be a web service call, I had to set the activating activity to true, to tell the workflow to start on the webservice call, Then the composition of the two other services was quite graphic, I didn’t touch to any code, I just had to right click on the workflow project and choose publish as asmx webservice.AND THATS ALL!!!To run the solution, u should start the host project, start the services, then call the orchestration service. I hope this could illustrate a little bit of goodness about .net 3.0 ! i ll try in future demos to involve transaction, thats where fun comes in :D ps:forgot to tell that WF xoml is an xml representation of the WF and can be exported as BPEL. Source Code in C#       

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress