First encounters of WWF
Recently I downloaded the Windows Workflow Foundation add-on for VS.2005 because I wondered what our Redmond friends had thought up here...
WWF is a framework full of classes and a visual designer to add workflow to your applications. It supports sequental workflows (the step-by-step kind) and state machine-like workflows.
I ran through some of the samples to see how it works. The samples don't get installed by setup, they are in a ZIP file in the folder wehre you installed the SDK (probably C:\Program Files\Microsoft SDKs\Windows Workflow Foundation); unzip them and go...
This is what you minimal do:
1. You design a workflow in the graphical designer. It comes with a toolbox full of workflow related shapes like all kinds of workflow steptypes (including calls out to web services of calls in from web services), connectors, if, while split and join flowcontrols, transaction context etc. From the design code is generated.
2. Create a simple application that creates a WorkflowRuntime object to run the workflow in.
class Program
{
static AutoResetEvent waitHandle = new AutoResetEvent(false);
static void Main()
{
// Start the engine.
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.StartRuntime();
// Load our schedule type.
Type type = typeof(WhileAndParallelWorkflow);
workflowRuntime.WorkflowCompleted += OnWorkflowCompletion;
workflowRuntime.StartWorkflow(type);
waitHandle.WaitOne();
workflowRuntime.StopRuntime();
}
static void OnWorkflowCompletion(object sender, WorkflowCompletedEventArgs instance)
{
waitHandle.Set();
}
}
3. Compile and run
The samples show what techniques can be used, from simple step-by-step workflows to complexer stuff like eventsinks and methodinvokes and transactional workflows
Then I looked at the WorkflowMonitor application sample. It shows you which workflows you have runned, which activities these workflows performed and the grapical schema of the workflow if it can find the assembly in which the workflow is implemented.
Setting up this sample requires some extra work. The application used the out-of-the-box SqlTrackingService. You have to create a tracking database and run some scripts.
1. If you only have SQLExpress that came with Beta2 (like I have) there is no Query Analyzer. You can create the database with the Database Explorer of VS.2005. Remind that the SQLExpress instance is called (local)\SQLExpress.
2. To run the scripts, add a new stored procedure and copy the contents of tracking_schema.sql, tracking_logic.sql (both put by setup in the folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\Windows Workflow Foundation\SQL) and monitor_queries.sql (in the main folder of the WorkflowMonitor sample) into it. Then select the whole, rightclick in the stored procedure editor's pane and click run selected...
3. Open the WorkflowMonitor solution and build it
4. Open another sample
5. Add the following Settings (under Properties\Settings.settings)
SqlTrackingService settings
| Name |
Type |
Value |
| type |
string |
System.Workflow.Runtime.Hosting.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 |
| ConnectionString |
string |
Initial Catalog=Tracking;Data Source=(local)\SQLExpress;Integrated Security=SSPI; |
| IsTransactional |
bool |
false |
| UseDefaultProfile |
bool |
true |
6. Add the following line of code to the WorkflowRuntime instance
workflowRuntime.AddService(new SqlTrackingService(Settings.Default.ConnectionString));
This will enable use of the SqlTrackingService in this sample too.
7. Build the sample and cop the complete contents of bin\Debug to the bin\Debug folder of the WorkflowMonitor sample
8. Run the WorkflowMonitor sample (supply your SQL Server name when requested), click the Monitor button to start monitoring and start the other workflow sample.
The monitor will show the workflow runned, its activities and its design
Now what should WE do with this?
Well:
1. there are samples in which this stuff is used for UI workflow (like a process layer...), or
2. backoffice processes (like BizTalk does). It needs some more exploring on how this should be done.
3. because a workflow is run inside a WorkflowRuntime object (in most of the samples a simple console app), an application hosted under IIS to run them remotely could be a nice study project.