Hello everybody,
I am planning to use Listen, Delay and event-based Activities in a sequential workflow like the one in the hands on labs WF HOLD01. In this case the manager can approve the report, otherwise it will be escalated if a certain time-limit is exceeded...
Now my question, how and where can I host the runtime if my architecture consists of web services (or respectively wcf in aspnetcompatibility mode) and the workflows take several days
So far I hosted the runtime in an Application variable and after each service request I saved the instances through the manualworkflowscheduler service in the database, but now I want to add a LISTEN Activity and inside a DELAY Activity which executes after 3 days, so I must not save the instances in the database but rather hold them in memory.
Should I use the cache instead Or a windows service Can anybody give me a short example how to store this kind of long running sequential workflow
Thanks in advance

Where can I host the runtime in a SOA based environment?
ShAdeVampirE
cool, many thanks, I never tested if the delay also works if the instance is frozen. I will try the alternative with the cache and tell you if I had success
Best regards
powerteh
Yes - ASP.NET recycles AppDomains - so you have your code check for the runtime and re-initialize it everytime the Application(AppDomain) comes back up. If you are using persistence it shouldn't really be a problem.
You can host in a windows service - but then you need to pick a communication mechanism between ASP.NET and the windows service (you might go with WCF here). But what happens if your windows service crashes Then windows restarts it - and there you are again with the same exact problem.
Fusion54
1) The AppDomains are recycled and the AppDomains come back up without anyone making a request. As long as you doing your Runtime initalization at the Application level the WorkflowRuntime will be re-created. There is a thread that services long-running workflows and delay activities in ASP.NET
2) Sure - as does the asp.net worker process
3) I don't have and I don't know of anyone who has a Windows Service with WCF hosting workflow. Maybe someone else does.
Jassim Rahma
Oh, thank you for the quick reply Jon, but where would you store the runtime with the services in a web service based architecture
lfnovo
The ExpenseReporting sample demonstrates a WCF service that hosts the workflow runtime as a WCF extension. The WCF service itself is hosted in a console app but it is trivial to host it in a windows service instead.
Here's the code (you'll need to replicate the config file as well). You can install this windows service using the installutil utility.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Configuration.Install;
using System.ServiceModel;
using IndigoUtil;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public ServiceHost serviceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost.Dispose();
serviceHost = null;
}
serviceHost = new ServiceHost(typeof(ExpenseLocalServices.ExpenseService));
// Create a new instance of our custom Indigo extension for
// ...managing the Workflow Service Container. Specify the
// ...config section to use for the WSC in the constructor of the extension.
WFIndigoExtension extWinWSIndigoExtension =
new WFIndigoExtension("WorkflowRuntimeConfig");
// Add the Extension to the collection from the Service Host
serviceHost.Extensions.Add(extWinWSIndigoExtension);
// Open the ServiceHost to create listeners and start listening for messages.
serviceHost.Open();
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost.Dispose();
serviceHost = null;
}
}
}
[RunInstallerAttribute(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller process;
private ServiceInstaller service;
public ProjectInstaller()
: base()
{
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = "ExpenseService";
Installers.Add(process);
Installers.Add(service);
}
}
}
Michael
tylerdn
Ok, thank you Michael. I will try this.
Simon
ChrisSmith
Simon,
>>Ahh, ok, i did not know that the AppDomains come back up without anyone making a request. Fantastic! Thank you!
Yes, the AppDomain comes back, but the Web Application starts on the first request, so if the web process is going to be recycled based on the events such as crash, idle time, number of requests, scheduler, memory resource, etc., always will wait for the first http request.
In other words, if your workflow uses a long running delay activity (for instance 1 day) and your web process in the IIS Application Pools has been recycled (overnight/idletime), then your workflow runtime will wait for its hosting in the Application_Start handler for the first request, also.
Another example: If you create a WebGarden for special purposes such as workflows, async processes (MSMQ receivers), remoting, scheduler, etc., in the IIS Application Pools, you have a responsibility to keep the web processes on live, for example, using a watchdog mechanism (pinging based on the number of worker processes).
Thanks
Roman
ShEi
"If you are using persistence it shouldn't really be a problem."
=> Ok, but what happens if nobody makes a request to the application for some days. Then no runtime is active, no workflow instance is restarted and nothing happens...
"But what happens if your windows service crashes Then windows restarts it - and there you are again with the same exact problem."
=> You are right, but then after the crash the windows service automatically starts (if it is configured so) and with the service the runtime.
"you might go with WCF here"
=> Yes, but I cannot find any sample how I could realize this. Do you perhaps have a little piece of code which shows how to communicate with the service Or at least a link how to make this run
Thank you in advance.
sunny123
Ahh, ok, i did not know that the AppDomains come back up without anyone making a request. Fantastic! Thank you!
But can you give me a little bit more information of "There is a thread that services long-running workflows and delay activities in ASP.NET".
Thank you Jon!!!
I will give a dedication in my diploma thesis! :-)
LittleSettler
ok, the solution with the workflow runtime in a Cache Variable that never expires works fine. But what happens when the AppDomain gets recycled Then the all the variables/objects "saved" in the cache of the AppDomain are also lost. Of course I can add the workflow runtime to the Cache for a second or a third time in the Application_Start event that occurs in the global.asax, but then I also have to wait till a request to my website/webservice is made.
And then I think this is a good solution for short running workflows, but not the best solution for a workflow running in a distributed environment on a web server if the workflow instance goes over several days.
For example if I have a DELAY Activity which should fire after three days if no other method is called - how can I realize this with the workflow foundation
I also read that this can be realized with a windows service, but I don`t know how and why. Could anybody give me a short example how I can communicate with a windows service which exposes the workflow runtime
Thank you all in advance
Best regards
Simon
Cissi
"Do you really expect no traffic on your site "
=> Yes, the application is for internal business processes only and so it could be that nobody makes a request for 2 days or longer.
If so I think I will favor the solution with the Windows Service.
Do you think that anybody of you professionals could post a little example for this szenario - how to host the workflow runtime in a windows service - to the sample gallery at www.netfx3.com
The workflow community and I would be very pleased with such an example and I believe that this szenario is required more often in the future if you are planning really long running workflows which should be available within a browser.
But thank you very much both of you. So far you have been a great help for me.
Best regards
Simon
Tryin2Bgood
davidwii
Paul Bates