posted on Tuesday, February 26, 2008 6:33 AM
by
BayerWhite
Keeping WF Runtime Alive While Hosted In IIS
There are a many benefits for hosting a Workflow Runtime through Windows Communication Foundation services in IIS. Most importantly, WCF services can leverage the functionality that IIS already does, for instance health management. IIS has the ability to recycle worker processes that enable it to run smoothly, but this can also affect long running workflows. There are some ways of getting around this, depending on how long a workflow can run, because IIS has a management tool for when it's processes get recycled. One way to do this is to recycle processes at certain times when you know client activity is going to be next to none, however if workflows are scheduled to run longer than a 24 hour period, you will still have problems.
Here is where the problem lies, when IIS recycles the runtime is stopped and not restarted, and since the persistence service is running within the runtime the polling stops for looking for expired workflow instance timers. The only hope you have is for a client to hit IIS and restart the Workflow Runtime, but for weekends and holidays, this can become a problem unless you can control a client request. There are many ways to manage the Workflow Runtime, but I am going to show you one that takes very little code. The ingredients' consist of a scripting file and Windows Task Scheduler. Here is a great link for understanding how the Task Scheduler works.
Follow these instructions for creating the script file and running it.
-
Create a new notepad file and rename the extension from .txt to .vbs
-
Add the following code to the file. All this code does is open Internet Explorer(IE) and call the WCF service hosted in IIS. Once the service is called IE is closed.
Set objIE = CreateObject
("InternetExplorer.Application")
objIE.Navigate("http://ServerAddress/Folder/ServiceName.svc")
Do Until objIE.ReadyState = 4
If (Wscript.Version > 5) Then
Wscript.Sleep 100
End If
Loop
Set objIE = Nothing
-
Now that the script file is completed it can be scheduled to execute by following the instructions for setting up a task within the Task Scheduler
So getting back to recycling IIS, once you set the schedule of when IIS needs to be recycled (usually when there is no traffic), the script file can be scheduled through the Task Scheduler to run maybe a couple of minutes(30) after IIS is recycled. The Workflow Runtime is now started back up after the recycle.