Windows Workflow Foundation and ASP.NET

My latest article shows how to drive an ASP.NET web form using a state machine workflow. The sample is based loosely on the Ordering State Machine smart client sample in the SDK, but adds a few real world requirements.

posted on Sunday, February 11, 2007 12:31 PM by scott Rated Excellent [4.33 out of 5].

Comments

Monday, February 12, 2007 5:16 AM by Steve

# re: Windows Workflow Foundation and ASP.NET


I haven't looked at it other than getting it installed on my machine, but the new Web Client Software Factory from the Microsoft Patterns & Practices group contains a Page Flow Application Block

http://www.codeplex.com/websf/Wiki/View.aspx?title=Page%20Flow%20Application%20Block&referringTitle=Application%20Blocks

Monday, February 12, 2007 12:08 PM by Ezequiel Jadib

# WF and ASP.NET

Windows Workflow Foundation and ASP.NET
Tuesday, February 13, 2007 4:56 AM by Thomas

# re: Windows Workflow Foundation and ASP.NET

System.Workflow.Runtime.Hosting.PersistenceException was unhandled by user code
Message="MSDTC on server 'NAME-2ARH9OD9A9\\SQLEXPRESS' is unavailable."
Source="wfOrderServices"
StackTrace:
bei wfOrderServices.OrderService.VerifyResults(WorkflowResults workflowResults, WorkflowStatus status) in C:\MyProjects\wfOrders\wfOrderServices\OrderService\OrderService.cs:Zeile 151.
bei wfOrderServices.OrderService.CreateOrder(Order order) in C:\MyProjects\wfOrders\wfOrderServices\OrderService\OrderService.cs:Zeile 28.
bei _Default.createOrderButton_Click(Object sender, EventArgs e) in c:\MyProjects\wfOrders\wfOrderWeb\Default.aspx.cs:Zeile 58.
bei System.Web.UI.WebControls.Button.OnClick(EventArgs e)
bei System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
bei System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
bei System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
bei System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
bei System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Tuesday, February 13, 2007 4:58 AM by scott

# re: Windows Workflow Foundation and ASP.NET

You'll need to turn on the MSDTC (Microsoft Distributed Transaction Coordinator) in your Services MMC.
Thursday, February 15, 2007 5:29 AM by Xeon

# Required MSSQL

Which version of database server is needed to run wfOrders.sql?
It drops error messages on MSSQL 2000
Thursday, February 15, 2007 7:27 AM by scott

# re: Windows Workflow Foundation and ASP.NET

Xeon:

I generated the script using SQL 2005. I'll update the help file to reflect this requirement, and the requirement to have MSDTC running.
Thursday, February 15, 2007 1:41 PM by Heng Wang

# re: Windows Workflow Foundation and ASP.NET

Hi, I read your ".NET 3.0
ASP.NET and Windows Workflows Foundation".

I download the source code. but I can not build it. Here is the error:

"Build (web): Could not load file or assembly 'PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
"

I even can not get OrderStateMachine.xoml design.
the error:

CreatedInstance failed for type 'UpdateOrderActivity'...

I did checked MSDTC and I changed the two parts of web.config and I did created the database wfOrders.

What I can correct the problem?

thanks
Heng Wang
Thursday, February 15, 2007 8:16 PM by scott

# re: Windows Workflow Foundation and ASP.NET

Hi Heng:

Are you sure you have the .NET 3.0 framework installed?

The workflow will not load in the designer until the it's dependencies build. Once everything builds you should be ok.
Friday, February 16, 2007 2:12 AM by Xeon

# re: Required MSSQL

Hi Scott,

I've tried with MSSSQL2005 Express and working now, but be aware of MSDTC settings described in Readme, on "3.5 MSDTC Is Not Fully Enabled on Windows" topic.

http://msdn.microsoft.com/vstudio/express/support/sqlreadme/

Regards,
Xeon
Friday, February 16, 2007 5:44 AM by scott

# re: Windows Workflow Foundation and ASP.NET

Thanks for the tip, Xeon. I added that link to the readme file.
Friday, February 23, 2007 10:24 AM by serg

# re: Windows Workflow Foundation and ASP.NET

Hi Scott,
I've tried wfOrders.sql and... take a look:


Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'ROLE'.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'ROLE'.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'ROLE'.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'ROLE'.
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.schemas'.
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.schemas'.
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.schemas'.
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.schemas'.
Server: Msg 170, Level 15, State 1, Line 19
Line 19: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 7

....... and so on .........
Friday, February 23, 2007 12:48 PM by scott

# re: Windows Workflow Foundation and ASP.NET

Hi Serge:

That seems odd. Is this on SQL 2005?
Sunday, February 25, 2007 11:28 AM by Luca

# re: Windows Workflow Foundation and ASP.NET

Hi scott, i've found your article very useful and extremely clear.
I'm actually get involved in learning and applying workflow in our web application and i'm playing with workflow foundation a bit.

I just want to write about a litte change that i've made to your code.

My requirement was to be able to use the WorkflowMediator without coupling it with a specific service(as like OrderService).

To do this the WorkflowMediator must be able to let someone else add two things:
1) add the specific data service
2) add the concrete ContenxtWrapper

The solution I've found was to add a static event to the WorkflowMediator class, add a call to that event in the AddService method and create and event handler for that event where the app starts(global.asax in the web app or in the main entry for console app).

WorkflowMediator class:

static public event eventHandler<WorkflowMediatorEventArgs> ServiceLoading;

protected virtual void AddServices()
{
if (WorkflowMediator.ServiceLoading != null)
{
WorkflowMediator.ServiceLoading(null, new WorkflowMediatorEventArgs(this));
}
}

WorkflowMediatorEventArgs class:

public class WorkflowMediatorEventArgs : EventArgs
{

private WorkflowMediator _workflowMediator;

public WorkflowMediator WorkflowMediator
{
get { return _workflowMediator; }
}

public WorkflowMediatorEventArgs(WorkflowMediator instance)
: base()
{
this._workflowMediator = instance;
}

}

And finally from my console app:

static void Main(string[] args)
{
WorkflowMediator.ServiceLoading += delegate(object source, WorkflowMediatorEventArgs e)
{
e.WorkflowMediator.ContextService = new MyContextWrapper();
e.WorkflowMediator.AddDataService(MyService.Instance);
};
Sunday, February 25, 2007 5:12 PM by scott

# re: Windows Workflow Foundation and ASP.NET

Excellent, Luca.

I took one approach in my code for my specific scenario, I'm glad other people are able to extend the code.

Sunday, February 25, 2007 11:49 PM by Luke's Blog

# Workflow Foundation in ASP.NET

Monday, February 26, 2007 12:42 AM by Stephan Smetsers

# Sequential workflow in ASP.NET

Hi,

You really should look at my freeware framework. It enables the use of sequential workflow in ASP.NET with just a few lines of code.

http://www.inchl.nl

demo video:
http://www.inchl.nl/recordings/inchl.framework.workflow.wmv

Stephan
Monday, March 05, 2007 1:31 AM by Patrick

# re: Windows Workflow Foundation and ASP.NET

Hi Scott,

I presented your sample to a talk at my local .NET user group last week. Quite some interested generated. I been looking for best practices on integrating WF to applications and I found your sample to be complete esp on the WF transaction. I am looking forward to integrate this code into my project.

BTW, when I enable SharedConnectionWorkflowCommitWorkBatchService service in web.config; my web page post back timeout. Any idea on how to make it work?
Tuesday, March 06, 2007 5:52 PM by Lucia

# re: Windows Workflow Foundation and ASP.NET

Hi,

I keep getting the following message, got any idea why?

Error HRESULT E_FAIL has been returned from a call to a COM component.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

Source Error:


Line 149: if (workflowResults.Exception != null)
Line 150: {
Line 151: throw workflowResults.Exception;
Line 152: }
Line 153: else

Wednesday, March 07, 2007 6:55 AM by scott

# re: Windows Workflow Foundation and ASP.NET

Lucia:

I'm not sure what could be happening there. Is there any details in the event log?