+44 (0)1179 113711

Rock Solid Knowledge Blogs

An aggregation of all the Rock Solid Knowledge Blogs

Subscribe  Subscribe

Executing Workflows from XAML Files

Seeing as this has changed completely from WF 3.5 I thought I’d post a quick blog entry to describe how to run a workflow declared in a XAML file.

You may have heard that the WF 4.0 default authoring model is now XAML. However, the Visual Studio 2010 workflow projects store the XAML as a resource in the binary rather than as a text file. So if you want to deploy your workflows as XAML text files how do you run them? In .NET 3.5 you could pass the workflow runtime an XmlReader pointing at the XAML file but in WF 4.0 there is no WorkflowRuntime class. It turns out you need to load the XAML slightly indirectly by creating a special activity called a DynamicActivity

DynamicActivity has an Implementation member that points to a Func<Activity> delegate – in other words you wire up a method that returns an activity (the workflow). Here’s an example:


static void Main(string[]
args)

{

  DynamicActivity dyn = new DynamicActivity();

 

  //
this line wires up the workflow creator method

  dyn.Implementation = CreateWorkflow;


  WorkflowInvoker.Invoke(dyn);

}


static Activity
CreateWorkflow()

{

  //
we use the new XamlServices utility class to deserialize the XAML

  Activity act = (Activity)XamlServices.Load(@"..\..\workflow1.xaml");


  return act;

}
Posted 17/12/2009 Richard Blewett

Demos from Last Week’s Guerrilla.NET

Thanks to everyone who attended Guerrilla.NET last week. As promised the demos are now online and you can find them here

http://rocksolidknowledge.blob.core.windows.net/demos/GNET261009.zip

Posted 02/11/2009 Richard Blewett