The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Workflow parameters in Window Workflow Foundation 4

Note: This blog post is written using the .NET framework 4.0 Beta 2

Creating parameters for a workflow is quite easy to do in WF 4. Just open the arguments tab in the workflow and add each input or output parameter you need and the required type.

image

 

Now in WF 3 passing data to a workflow was done using a Dictionary<string, object> to specify the input. This is very flexible but also very brittle as it is all magic of key names matching property names. This approach still works as the following code demonstrates.

var input = new Dictionary<string, object>();
input["FirstName"] = "Maurice";
input["LastName"] = "de Beijer";
var result = WorkflowInvoker.Invoke(new Workflow1(), input);
Console.WriteLine(result["Greeting"]);

 

However WF4 has a new approach that includes full type safety. Every time you create an in or out argument the workflow will also get a corresponding public property. These properties are of type InArgument<T> but they contain an implicit cast from T so the code is quite easy as shown below.

var workflow = new Workflow1();
workflow.FirstName = "Maurice";
workflow.LastName = "de Beijer";
 
var result = WorkflowInvoker.Invoke(workflow);
Console.WriteLine(result["Greeting"]);

 

Much cleaner!

Unfortunately the OutArgument Greeting is there but printing it’s contents to the console only results in the type being printed. There is also a Get() method but this requires an ActivityContext to be passed. So in the case of output we are still restricted to using the Dictionary<string, object>.

 

Enjoy!

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Published Fri, Oct 23 2009 21:17 by Maurice
Filed under: , ,