Friday, September 29, 2006

Some of you are requesting example applications that are using the PageFlow tools.  Please be patient.  I am working out bugs in the project on a real world rewrite of the Pets Best enrollment process.  Until I have it working well enough a robust example application is not possible.  There are still some aspects of workflow that are not completely clear and thus result in some challenges in the toolkit.  It is mostly working.  The page flow aspects are working great to drive navigation.  I am now pushing through the remaining challenges with sending objects (data) from a workflow back to the application in a way that will work consistently with persisted workflows.

9/29/2006 5:35:53 PM (Mountain Daylight Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, September 19, 2006
After a couple months of being sidetracked on a different project I am now back on the ASP.NET Page Flow project again.  I am pleased to announce that I also have a CodePlex project for it.  I encourage everyone who is interested to join the project, get the code and start making suggestions and contributions.  I will be putting it to its first use on the Pets Best Enrollment process.  Over the next 4 weeks I will be working with the Pets Best team to perfect the starter kit to a point where it can be trusted for a production release with their Pet Insurance enrollment process.
9/19/2006 5:21:42 PM (Mountain Daylight Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, June 26, 2006

This post will introduce the first part of a starter kit for doing Page Flows in ASP.NET with Windows Workflow.  The first Release Candidate for Workflow is now out as part of the June .NET 3.0 CTP.  If you are already working with the Beta's you will need to update your SQL Persistence and Tracking databases with the new scripts.

I have put in a request to CodePlex to host the starter kit.  I will add an update to this blog once it is approved.

The first thing the starter kit contains is the necessary configuration to get a PageFlow project started.  As I started learning workflow I discovered that there are several things required for using it from an application.

Hosting the Runtime

Windows Workflow does not offer any out of the box servers or special applications to take advantage of it.  It is entirely up to developers to host the Workflow runtime inside of an application.  This could be a Windows service, a .NET web service, a Windows application or an ASP.NET application.  The only requirement is that host can work with the .NET 3.0 Workflow assemblies.  In our case we will focus on hosting inside of ASP.NET.

The runtime only needs to be created once per application in order to host multiple workflows.  The blogs and examples I have found so far recommend creating the runtime in the global.asax.cs file.  I have chosen in the starter kit to instead use an httpModule.  By using a module it is easier to add Workflows to existing applications without having to cut and paste code.

All that is needed is to create an instance of WorkflowRuntime and then shove it into an application variable that we can access later in our ASP.NET pages.  We will use this variable in a PageFlowManager control so that direct interaction with the runtime is not even necessary from our applications. 

               WorkflowRuntime workflowRuntime = new WorkflowRuntime("WorkflowRuntime");
               context.Application["WorkflowRuntime"] = workflowRuntime;
               workflowRuntime.StartRuntime();

There are 2 important additional items to note in the code above.  When creating the runtime the constructor takes a configSectionName as string.  That string matches the workflow configuration element name in the web.config.  I find that consistently naming it keeps it simple and easy to manage.  The code would have to be changed if you named it something different.  The second thing is that StartRuntime is called.  This allows the runtime to read the configuration and initialize all of the services that you have added via the configuration itself.

Configuration

Lets take a look as what is in the basic configuration.

First we define a config section for the WorkflowRuntime.  Note that the name matches the name passed to the constructor when creating the runtime.

<configuration>
   <configSections>
      <section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   </configSections>

We add a reference to the httpModule that initializes the runtime for us.

   <system.web>
      <httpModules>
         <add name="AspNetPageFlow" type="AspNetPageFlow.WorkflowRuntimeModule, AspNetPageFlow"/>
      </httpModules>
  <system.web>

Finally we configure the runtime with the typical services we need for most workflows.  Note that the root element of the section matches the name given when creating the configuration section above.  The services added via configuration are automatically loaded by the runtime when it starts.  Services can also be added via code, but for the common ones it makes sense to me to just put them in config.

   <WorkflowRuntime Name="WorkflowServiceContainer">
      <CommonParameters>
         <add name="ConnectionString" value="Data Source=.\SQLEXPRESS;database=WFServices;Integrated Security=True;"/>
      </CommonParameters>
      <Services>
         <add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UnloadOnIdle="false"/>
         <add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UseDefaultProfile="true" IsTransactional="false" ProfileChangeCheckInterval="60000" PartitionOnCompletion="false"/>
         <add type="System.Workflow.Activities.ExternalDataExchangeService, System.Workflow.Activities, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </Services>
   </WorkflowRuntime>
</configuration>

The CommonParameters section is nice because it allows us to share configuration for elements that have the same configuration.  In our case we are sharing a database for Workflow tracking and persistence.  You will find the SQL scripts at C:\windows\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN for the latest release anyhow.

The other services we have added here are the ManualWorkflowSchedulerService and the ExternalDataExchangeService.  The ManualWorkflowSchedulerService was created specifically for ASP.NET.  It requires us to do a little more management because we have to explicitly run the workflow when we need it.  This will be a non-issue once we add the PageFlowManager to our pages, but nevertheless it is required.  What this service does is it allows the runtime to borrow the current thread from ASP.NET itself.  That is important to understand as it will have affect on security and page postbacks.  A separate thread is automatically managed by the runtime for delay activities, but otherwise ASP.NET hosted workflows run in the same thread as the hosting application.

Just today I read that the ExternalDataExchangeService should be unique for each workflow instance.  I need to do a little more research on this one and I may amend this post if that is indeed true.  This service is used for communication between the host and the workflow.  We will use it with a simple data pipe service in order to simplify sending objects back and forth between the host and the workflow.  Of course the complexties involded will be wrapped up into the PageFlowManager and some workflow activities to make our jobs much easier.

In a future post I will examine the PageFlowManager and how it keeps the pages and the workflow in sync driving navigation and abstracting the management of the runtime from the application developer.

6/26/2006 11:17:13 PM (Mountain Daylight Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Sunday, June 18, 2006

Having just returned from TechEd 2006 I am excited to begin sharing my passion for Windows Workflow Foundation (WF).  It is my opinion that WF is the tool that will enable model driven development that will become the de facto standard for application and system development.  If you are not familiar with WF yet, then its time to start reading up on it over at www.netfx3.com.  Currently Microsoft is shipping WF beta 2.2 with both Sequential and State Machine workflow activities.  Later this year they are planning to release WF and a CTP of a new WF activity know as PageFlow.  While you wait you might check out the Webcast from Israel Hilerio to see some of the ideas going into the page flow activities.  I really enjoyed meeting Israel and the other members of the WF team as well as Kashif Alam.  Kashif is the point of contact for the ASP.NET team when it comes to WF integration and the coming Page Flow activities.

I have spent the last few weeks trying to build a page flow model on top of a State Machine since I was not aware of the model Microsoft is working on.  Now that I have a better understanding of where Microsoft is heading as well as a working prototype of my own I would like to begin sharing my code and ideas.  I look forward to other feedback and ideas for improvement.  I am ready to use WF now!  My hope is that, together with anyone who reads this, we can create and maintain a set of tools that will enable powerful WF solutions underneath very thin UI layers. 

I will be focusing on starting a WF powered web application from scratch.  What will make it different from a traditional application is that all logic and flow will be driven by the WF engine, activities, and abstraction layers.  In the end I will have a web UI that is completely brainless.  All short and long term persistence will be managed by WF activities and WF code.  All navigation and page flow will be driven by WF models, yet equally supportive of non-linear processes and browser back buttons.  Running a Windows UI on top of the workflow will be fully supported, though at this time I do not plan to explore that scenario, except to ensure that system.web is not referenced anywhere except the UI layer.  I will be demonstrating an ASP.NET WorkflowManager (WFM), but it should be trivial to create a similar Smart Client WorkflowManager as well.  The WFM will by the abstraction layer between the UI and the WF making it simple for the developer to pass objects between the 2 and manage the runtime and WF instances.

In addition I will share my implementation of the Simple Read and Write activities that were introduced in the MS Help Desk sample application.  The Help Desk sample application was also written by Israel Hilerio to demonstrate an option for simplifying the sharing for data between a workflow and the hosting application.  I have found it to be very effective for many scenarios and I look forward to presenting some enhancements to it for enabling additional scenarios.  These will be incorporated into the WFM and added to the WF Runtime as DataExchange services.

I look forward to interacting with the WF community so fell free to introduce yourself and comment with questions as I post articles and code.

 

6/18/2006 9:19:04 PM (Mountain Daylight Time, UTC-06:00)  #    Disclaimer  |  Comments [2]  |  Trackback