LinkedIn

Saturday, 2 October 2010

Workflow 4.0 - Hosting with AppFabric

Following on from my last post I will attempt to share with you, the steps I took to get my workflow hosted in AppFabric with Persistence and Monitoring enabled.(I will not talk about AppFabric's caching abilities as I know nothing about these at this point!!)


Ok so from my first post which is here:
http://russellmccloy.blogspot.com/2010/10/workflow-40-sample-development.html

I outlines how I began with workflow 4.0 and a few of the issues I had. I eventually got to a point where I developed a workflow application that, in a very simple way, allowed for the approval of an expense.


what I will now try to talk about is getting that workflow and it's parts hosted in AppFabric.


To start with, I created the workflow project as follows in this pic:
Workflow project creation
When you create a new WCF Workflow Service Application the settings default to using the visual Studio 2010 development server. If we want to use AppFabric we need to change the project so that it is hosted, first of all in IIS. The following picture shows this:
Visual Studio Project Properties
If you use the "Create Virtual Directory" button, then VS 2010 will, hopefully create the IIS vertual directory for you as shown here:
IIS virtual Directory
Right so we now have a Wcf service in IIS but it's sort of useless unless we built our own monitoring and hosting tools. Remember that AppFabric gives you loads of stuff out of the box. It also manages hosting and will re-hydrate a workflow from the persistence store when a delay timer expires.

So now what we need to do is install AppFabric.

Once appFabric is installed you need to configure appFabric.


To configure AppFabric click on the following link:

You will get an explanation page:

then the connection setup page for your monitoring and persistence database:

Before you point to the database you will need to run the following scripts that are @:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\SQL\en:
SqlWorkflowInstanceStoreSchema.sql
and
SqlWorkflowInstanceStoreLogic.sql


the setup wont work with out these. I think they setup a basic persistence store and appFabric then adds additional functionality to it. Not sure right now.

After you run these 2 scripts successfully on the database of your choice. (You can use any SQL db with any name to store persistence and monitoring data) you can then continue with the AppFabric setup. You may get a warning about Sql agent not being detected as in a runnable state but I checked and mine was running so I think you can assume everything is still ok.



Following this you should get a success message. 


And then a final restart IIS message:

Note: I did not select to setup the caching part of AppFabric.

After this you need to configure the local details for your site / xamlx service hosting in IIS and AppFabric. The setup we have just done relates the overall global setting for our IIS / AppFabric server. We can get more granular at the site level:


Setup monitoring. Accept default as specified earlier and add some trace and message logging as shown in the following pics:



You may get an issue with net.pipe missing. You can add this in the sites advanced settings as shown below:


After this is done we can run our windows client in Visual Studio. The windows client submits expense requests to our workflow.


Before we do this please not that I have neglected to add the c:\MailboxExpenseApproval directory on my server.   This will enable us to see the workflow experience and error and "suspend" its self. Using AppFabric we will be able to add the directory  to the file system and "resume" the workflow. 


So here is the windows client


You can see that after submission we get an error:




It looks like an Smtp error because c:\MailboxExpenseApproval directory on the server is set as the pickupDirectory for sending mail. As it's not there, we get an error which is good for us right now.


If we look in AppFabric we will see that the workflow is suspended:

We can then add the c:\MailboxExpenseApproval directory and then resume the workflow using AppFabric.Nice!! 


I have then build a web site that is hosted in the same IIS / appFabric as the xamlx service. The website is used to response the the Smtp emails that managers receive asking them to approve expenses. There are links in the emails to point to the approve / reject form:




Once approved the user will see this message:


The persisted instsance of the workflow will then complete and be automatically removed from the persistence store. (Note: you can set some config to keep completed persisted workflow instances if you prefer).

That's all for now. Will add more later.

RuSs