I am a skeptic person. Always be.
I will always challange whether something is true until I cannot proof otherwise. (But then I will challange it back again once I found another proof though...).
This time it's about Windows Workflow Foundation (WF). I was always worried that it is not safe to host WF in ASP.NET. I was questioning the Workflow Runtime, Thread / Asynchronous Issue, Memory Issue and Web Farm Scenario Issue.
I happened to read these two articles: http://msdn.microsoft.com/msdnmag/issues/06/04/cuttingedge/default.aspx
They convinced me that it is safe to host Windows Workflow Foundation in ASP.NET. Below are the questions I had, and how WF deals with those issues:
Single Workflow Runtime Issue
Workflow Runtime to be created in global.asax, then in every request that needs the runtime we can use WorkflowWebRequestContext.Current.WorkflowRuntime so that it guarantees only one Workflow Runtime is used within the web application AppDomain.
Thread / Asynchronous Issue
We can use ManualWorkflowScheduler service so that workflow will not run asynchronously, rather, it will serialized the workflow instance so that the workflow instance will run synchronously within a page life cycle. ASP.NET pooled thread will be in charge of executing the current request waits until the workflow is completed or in idle state.
We can use WorkflowPersistenceService that will passivate/persist workflow instance in a given state into a database after each page request (see above). So, a workflow instance won’t sit in memory until the instance is called again by another page request. This guarantees memory won’t be occupied by long running workflow instance.
Web Farm Scenario Issue
It is clear that WorkflowPersistenceService work like Out Of Process State Management (SQL Server State), so that it supports web farm scenario. It allows multiple Web servers to handle the page requests without the request having to go back to the same server as workflow instance is stored in database (just like SQL Server State store session objects). All we need to do is activate the sleep workflow instance by giving the right instance id.
I have other questions about WF, but that is WF in general and got nothing to do with ASP.NET. And just speaking about hosting WF in ASP.NET, it's safe. I'll keep you posted on my journey digging this API.
O, and I am reading Dharma Sukla's "Esseintial Workflow Foundation" now. Good book, but I suggest you to see more introductory level books/articles and play around with the WF API first. This is the kind of book like Don Box's "Essential .NET", you'll lost if you haven't read other book about .NET.