Introduction to Workflow 4

Version: 1.1.0

Description

In this lab you will get to know the basics of creating, hosting and running a workflow. This lab is also intended to be and introduction to the new workflow authoring constructs in the .NET Framework 4 and Visual Studio 2010, including the new Workflow Designer, expressions, variables and arguments. Additionally, you will explore the use of some basic built-in activities.

Overview

Welcome to Windows Workflow Foundation 4 (WF) Microsoft's programming model, engine and tools for quickly building workflow-enabled applications. This release of WF in .NET Framework 4 changes several development paradigms from previous versions. Workflows are now easier to create, execute, and maintain.

In this lab, you will get to know the basics of creating, hosting and running a workflow. This lab is also an introduction to the new workflow authoring constructs in the .NET Framework 4 and Visual Studio 2010, including the new Workflow Designer, expressions, variables and arguments. Additionally, you will explore the use of some basic built-in activities, create custom activities, activity designers and even re-host the workflow designer in a WPF application.

Note:
Do I have to do all the exercises?

This lab is long. To do all of it will probably take close to 2 hours. This lab has been designed so that each exercise is independent of the others. Just open the solution found under the Begin folder for the exercise. For example, if you wanted to learn how to create a custom activity designer you would start with Exercise 9 and open the solution from the Source\Ex9-ActivityDesigner\Begin folder

Objectives

In this Hands-On Lab, you will learn:

  • How to create a sequential workflow using the designer and XAML or, alternatively, using plain C# or Visual Basic code
  • How to run and test the sequential workflow using the WorkflowApplication and WorkflowInvoker classes
  • How to pass InArguments and receive OutArguments from a workflow
  • How Expressions and Variables are used
  • How to use the WriteLine, If, TryCatch, Catch<T> and Throw activities
  • How to load and run an activity from a xaml file
  • How to create an activity designer
  • How to host the WorkflowDesigner in your own application

System Requirements

You must have the following items to complete this lab:

  • Microsoft Visual Studio 2010
  • Microsoft .NET Framework 4

Setup

All the requisites for this lab are verified using the Dependency Checker. To make sure that everything is correctly configured, follow these steps:

  1. Run the Configuration Wizard for the Training Kit if you have not done it previously. To do this, browse to Source\Setup folder of this lab, and double-click the Dependencies.dep file. Install any pre-requisites that are missing (rescanning if necessary) and complete the wizard.

    Note:
    The Configuration Wizard is used for checking dependencies and setting up the environment. If the Configuration Wizard is not installed on your machine, you must install it running the DependencyChecker.msi file located on the %VS2010TKInstallationFolder%\Assets\DependencyChecker folder (e.g. by default the Training Kit is installed under C:\VS2010TrainingKit).

    For convenience, much of the code you will be managing along this hands-on lab is available as Visual Studio code snippets.

    To use code snippets with XAML, right-click on the xaml file, select Open With and choose XML Editor. Then you can insert XML snippets into the file.

Exercises

This Hands-On Lab comprises the following exercises:

Note:
Note: each exercise builds on the one before it but you can start at any point in the lab by opening the solution in the Begin folder for the exercise.

  1. Hello Workflow
  2. Refactoring Workflow
  3. The CodeActivity
  4. Dynamic Workflows with XAML
  5. Testing Workflows
  6. WorkflowApplication
  7. Adding If/Else Logic
  8. Error Handling
  9. Custom Activities and Designers
  10. Hosted Designer

Estimated time to complete this lab: 120 minutes.

Starting Materials

  • Visual Studio solutions. Depending on the exercise you will find Visual Studio solutions for C# and Visual Basic that you can use as starting point for the exercises.
Note:
What if I get stuck?

The source code that accompanies this hands-on lab includes an end folder where you can find a Visual Studio solution with the code that you would obtain if you complete the steps in each exercise. You can use this solution as a guide if you need additional help working through the exercises.

Remember to build the solutions before opening any file using the workflow designer.

Next Step

Exercise 1: Hello Workflow