Jon Flanders' Blog

Using WF to run a page-flow

Friday, March 17, 2006 5:45:42 PM (GMT Standard Time, UTC+00:00)

There are many really great things about using workflow as the logic behind your application.  The one that really excites me is the visibility workflow gives you into what your application is doing.

 

Another great thing is that many types of applications are naturally workflows, and so using workflow for those applications is really a no-brainer.  One of the most-often cited examples is page flow in ASP.NET.   Moving a user from page to page in an ASP.NET application is really a workflow.

 

Now, until the ASP.NET team and WF team come out with something official in terms of integration, using WF as page-flow is going to be kind of ad hoc.  Here is my take on one way to do this.

 

Here are the goals I had in mind when I built this sample (which is based partly on other applications I have built already using WF and ASP.NET).

 

1)   The WF and the ASP.NET Pages should be unaware of each other.  ASP.NET shouldn’t know it is being run by a workflow, and the workflow shouldn’t know it is being called from ASP.NET.

 

2)  The ASP.NET model should be preserved.  What I mean by this is that ASP.NET pages should be written using a control-based, data-bound methodology.  I also am a big fan of ASP.NET 2.0 and all the work they have done to make building pages easier.  Some other examples of using WF with ASP.NET I’ve seen make the pages go out of the regular model.  IMO – there is a reason for the page model in ASP.NET and I wanted to try to preserve that model in my integration.  So this means using server-side controls and events, along with data-binding.

 

Here is an overview of this sample.  First – there is a state-machine based workflow.  Although a sequential workflow would work, state-machine is really more appropriate for this scenario (see Dave Green’s post here about the two different models).

 

The workflow takes as parameters an OrderedDictionary and a string.  The OrderedDictionary holds onto the real parameters.   The reason I use an OrderedDictionary is to make the ASP.NET model easier to use.  With declarative data sources in ASP.NET 2.0, generally the data source control takes care of processing the form data (and other data, like sessions or cookies) by using a ParameterCollection.  The ParameterCollection is made up of Parameter objects which are responsible for extracting data from controls, the session object, or other objects.   The data source control can then use this to actual perform CRUD operations.   The idea is that the page can be written using the normal model – and then the parameters are gathered by the data source control, and rather than have the parameters processed by the data source, the parameters are passed into the workflow.   My concept here is to let ASP.NET developers write pages using their regular model and then integrate with WF seamlessly.

 

So this could be done by using an existing datasource and extracting the parameters:

 

base._params = SqlDataSource1.SelectParameters.GetValues(HttpContext.Current, SqlDataSource1) as OrderedDictionary;

 

Or by manually packing up parameters into an OrderDictionary instance:

 

//manually create the parameters
this.Parameters = new OrderedDictionary();
this.Parameters.Add(TextBox1.ID, TextBox1.Text);
this.Parameters.Add(TextBox2.ID, TextBox2.Text);

  

The other parameter to the workflow is just a string.  This is what I call the “command”.   The concept is that the page will pass a “command” to the workflow, and then based on the way the workflow is written, the workflow will pass back to the page the next “command”.  Based on the next command value, the integration layer between the pages and the workflow will redirect to the next page.  The next page value is also based on configuration.   The idea is that the configuration mapping will control what page is next in the flow, and that the workflow will just be passing back the next “command” which will then be mapped in configuration to a page.   This keeps the workflow from knowing it is running a page flow and the page from knowing it is using a workflow.

 

After the workflow starts, it continues to live (placed in ASP.NET session) and then is invoked for the rest of the page flow.  The workflow instance then waits for communication from the host (which is really implemented in a single class called WorkflowWrapper).  These events (a custom activity based on HandleExternalEvent – generated using the wca.exe tool) also take an OrderedDictionary and a string.  The events also use correlation; this is why the external data exchange interface only needs on event.

 

 

The CallExternalMethod activity passes back to the host (through the local service implementation) a DataSet, and the “next” command.  The next command is used to redirect based on the configuration, and the DataSet is placed in ASP.NET Session.   When the next page is executed (after the redirect) the page can extract the DataSet from ASP.NET Session (all the operations of each page is actually wrapped in a BasePage class implementation).

 

 

The other interesting thing about each ASP.NET page is that none of them directly calls the workflow or handle control events.  The base page class does this.  Rather than limit the kind of controls that each derived class can use, the base class overrides OnBubbleEvent, and then just extracts the control as an IButtonControl, which means this will work with Button, LinkButton, or ImageButton (to handle other kinds of controls that post-back this method would have to be modified).

 

The local service and the event activities are separated into a separate library – as is the workflow.  To make this same example work with say a set of Windows Forms – there is just one line of code in the local service implementation that would need to be changed (the line that stores the result of the CallExternalMethod in the HttpContext.Items collection).

 

In this example – Default.aspx is the first page in the flow.  It has two text boxes, the values of which get passed to the workflow.  The next page is Page2.aspx and it gets two DataTables from the DataSet and uses it to bind a GridView and a DropDownList.    The rest of the pages just flow – there isn’t any really functionality going on with them.  If you go into the web.config – you can move pages around in the configuration and make the flow of the pages different.

 

I probably will have more to write about on this topic – so this is just the first post.  I am interested in ideas of comments anyone has on this topic, so feel free to critique my design – as I said this is just my beginning thoughts on how to use WF with ASP.NET – my next task is to create a custom datasource control for WF specifically.

aspnetwfpageflowexample.zip (127.88 KB)

 |    #    Comments [13]   Tracked by:
"ASP.NET/WF Integration" (Ryan McIntyre) [Trackback]
"User Interface Page Flow with WF" (Paul Andrew) [Trackback]
http://veda.parivedasolutions.com/blogs/brianorrell/archive/2006/03/29/30.aspx [Pingback]
"Windows Workflow Foundation mit ASP.NET nutzen" (Alex on ASP.NET) [Trackback]
http://blogs.dotnetgerman.com/alexonasp.net/PermaLink,guid,70f9fa35-2821-49c3-87... [Pingback]
"Jon Flanders on Windows Workflow Foundation and ASP.NET" (Kirk Allen Evans' Blo... [Trackback]
"Coming improvements to ASP.NET hosting of Windows Workflow Foundation after WF ... [Trackback]
http://blogs.msdn.com/pandrew/archive/2006/04/28/586181.aspx [Pingback]
"Windows Workflow Foundation Resource List" (MarcosT Blog) [Trackback]
"Windows Workflow Foundation Resource List" (MarcosT Blog) [Trackback]
"Windows Workflow Foundation Resource List" (MarcosT Blog) [Trackback]
"Utilisez Windows Workflow Foundation avec ASP.NET" (RedoBlog - The .NET Gentlem... [Trackback]
"WF PageFlow Cleverness" (the roarty blog) [Trackback]
"Reactive Web Development versus Continuations" (K. Scott Allen) [Trackback]
"Talk Resources: WF & ASP.NET" (this.Pose() as Expert) [Trackback]
http://chrison.net/TalkResourcesWFASPNET.aspx [Pingback]
"maryland automotive windshield" (maryland automotive windshield) [Trackback]
"her first audition" (her first audition) [Trackback]
"annuncio affitti isernia" (annuncio affitti isernia) [Trackback]
"paul posey tallahassee florida" (paul posey tallahassee florida) [Trackback]
"georgia bulldog" (georgia bulldog) [Trackback]
"cd organizers" (cd organizers) [Trackback]
"offerta praga" (offerta praga) [Trackback]
"female body builders posing" (female body builders posing) [Trackback]
"congelatore da incasso" (congelatore da incasso) [Trackback]
"cameriere in autoreggenti" (cameriere in autoreggenti) [Trackback]
"Sports Betting Rss Feed" (Sports Betting Rss Feed) [Trackback]
"albuquerque respiratory jobs va medical center" (albuquerque respiratory jobs v... [Trackback]
"tiaras and headpieces" (tiaras and headpieces) [Trackback]
"used kountry aire camper trailer" (used kountry aire camper trailer) [Trackback]
"columbus ohio commercial real estate" (columbus ohio commercial real estate) [Trackback]
"invisibile pulcino dildo" (invisibile pulcino dildo) [Trackback]
"sms gratis cellulare" (sms gratis cellulare) [Trackback]
"racconto erotici con animali" (racconto erotici con animali) [Trackback]
"zyban side affects" (zyban side affects) [Trackback]
"downlineincome.com" (downlineincome.com) [Trackback]
"www.pokerplayersusa.com" (www.pokerplayersusa.com) [Trackback]
"www.mommyco.com" (www.mommyco.com) [Trackback]
"www.cannabisvaporizers.com" (www.cannabisvaporizers.com) [Trackback]
"www.feminizedmarijuanaseeds.com" (www.feminizedmarijuanaseeds.com) [Trackback]
"www.bewbs.com" (www.bewbs.com) [Trackback]
"hackgs.com" (hackgs.com) [Trackback]
"www.neptunesbeachclub.com" (www.neptunesbeachclub.com) [Trackback]
"www.conferencecalldirectory.net" (www.conferencecalldirectory.net) [Trackback]
"www.ringtone-center.com" (www.ringtone-center.com) [Trackback]
"www.herbalmarijuanavaporizer.com" (www.herbalmarijuanavaporizer.com) [Trackback]
"www.herbvaporizers.com" (www.herbvaporizers.com) [Trackback]
"www.marijuanavapor.com" (www.marijuanavapor.com) [Trackback]
"www.jntah.com" (www.jntah.com) [Trackback]

Navigation

Books

Courses

Search

Subscribe

  • RSS 2.0
  • Add to Windows Live button
  • Add to Google button
  • Add to MyMSN button
  • Add to MyYahoo button
  • Add to Bloglines button
  • Add to Newsgator button