Book Image

Microsoft Windows Workflow Foundation 4.0 Cookbook

By : Andrew Zhu
Book Image

Microsoft Windows Workflow Foundation 4.0 Cookbook

By: Andrew Zhu

Overview of this book

Windows Workflow Foundation 4.0 (WF) is a significant part of .NET Framework 4.0. WF makes workflow technology available to every single programmer that uses the .NET Framework 4.0. It is easy to create long running and distributed programs using WF with the right knowledge. With this book, you will discover that working with workflows is easy. This book provides both step-by-step recipes and relevant background information. It covers all the important aspects of Windows Workflow Foundation 4.0. The best thing about this book is that all recipes are based on real-world experiences of Andrew Zhu. Andrew is a global WF and BizTalk technology support engineer for Microsoft. This book covers everything you need to know, when working with workflows. Get to grips with flow control activities, messaging, and transaction processes with easy to understand steps followed by explanations. You will quickly learn to use collection and custom WF activities and WF services.You will see recipes that illustrate integration of Windows Workflow with other applications such as WPF, ASP.NET, WCF service.Lastly, you will discover how easily you can customize W4 Designer with WF rule engine and others.
Table of Contents (15 chapters)
Microsoft Windows Workflow Foundation 4.0 Cookbook
Credits
About the Author
About the Reviewers
Foreword
Preface
Index

Creating the first WF program: HelloWorkflow


In this task we will create our first workflow to print "Hello Workflow" to the console application.

How to do it...

  1. Create a Workflow Console Application project:

    After starting Visual Studio 2010, select File | New Project. A dialog is presented, as shown in the following screenshot. Under the Visual C# section, select Workflow, and choose Workflow Console Application. Name the project HelloWorkflow. Name the solution Chapter01 and make sure to create a directory for the solution.

  2. Author the workflow program:

    First, drag a Sequence activity to the designer from Toolbox, next drag a WriteLine activity into the Sequence activity. Finally, input "Hello Workflow" in the expression box of the WriteLine activity. We can see in the following screenshot:

  3. Run it:

    Press Ctrl+F5 to run the project without debugging. The result is as shown in the following screenshot:

How it works...

When we press Ctrl+F5, Visual Studio saves the current project, and then it runs the project from the Main method in the Program.cs file.

WorkflowInvoker.Invoke(new Workflow1());

The preceding statement starts the workflow. After the workflow starts running, the WriteLine activity prints the "Hello Workflow" to the Console Application.

The workflow we created in WF Designer is actually an XML file. We can open Workflow1.xaml with an XML editor to check it.

Tip

Right-click on Workflow1.xaml then click Open With…, and choose XML Editor to open Workflow1.xaml as an XML file.

All XAML files will be compiled to .dll or .exe files. That is why when we press Ctrl+F5, the program just runs like a normal C# program.

There's more...

So far, there are no officially published WF4 Designer add-ins for Visual Studio 2008. We need a copy of Visual Studio 2010 installed on our computer to use WF4 Designer, otherwise we can only create workflows by imperative code or by writing pure XAML files.