Search This Blog


Tutorial 1:Create a Simple Workflow

A tutorials on Windows workflow Foundation(WWF),Step by step tutorials on Windows workflow Foundation(WWF),A biginner tutorials on WWF
Create a Hello World Workflow
In this exercise, you will create a very simple “Hello World” workflow using the Visual Studio 2005 designer for Windows Workflow Foundation, referred to as the Visual Studio workflow designer in the remainder of this document. The Hello World workflow will be a sequential workflow that includes a single code activity. The code activity will be used to write the phrase “Hello, World!” to the console at runtime. You will explore the workflow definition and the code-beside for the workflow. Finally, you will see how to execute your workflow using a simple host and debug your workflow using Visual Studio 2005.
Task 1 – Create a new Workflow Project

1. Open Visual Studio 2005 by going to the Start Menu Programs Microsoft Visual Studio 2005 Microsoft Visual Studio 2005
2. In Visual Studio 2005, select the File New Project menu command.
3. Visual Studio 2005 will display the New Project dialog window.
4. In the New Project dialog window, expand Visual C# Workflow in the Project Types tree on the left side.
5. Select the template named “Sequential Workflow Console Application” and enter the following values:
Name: HelloWorldWorkflow
Location: C:\Windows Workflow Foundation\Labs\Lab01

6. You should now have a new solution and workflow project.
7. The project template has a Workflow1.cs which we will remove as we will be using a simpler kind of workflow for this lab. Click on Workflow1.cs and press the DEL key. Click the okay button to confirm.
8. Right click on the HelloWorldWorkflow project in Solution Explorer and select Add New Item from the context menu.
9. In the Add New Item dialog window, select the item template named Sequential Workflow (with code separation) and click the Add button to add the new workflow to the HelloWorldWorkflow project.

Note: It may be easier to read the template names if you change the view of the Add New Item dialog to large Icons by clicking on the toolbar icon in the upper right corner.

10. The new Sequential Workflow project will now contain two files: Workflow1.xoml and Workflow1.xoml.cs. Workflow1.xoml contains the XML markup that represents the workflow type. Workflow1.xoml.cs contains the code-beside class for the workflow.

Task 2 – Add a code activity

1. Double click on the Workflow1.xoml file in Solution Explorer to open the Visual Studio workflow designer.
2. In the workflow designer, select the View Toolbox menu command to display the toolbox with available activities.
3. You may need to expand the Windows Workflow category in the toolbox to view the Windows Workflow Foundation activities.

4. Select the Code activity from the toolbox.
5. Drag and drop the Code activity to the design surface for the Sequential Workflow.
6. Notice the red exclamation mark on the new Code activity. Click the exclamation mark to view the smart tag and the reason for why it’s being displayed.

7. Selecting the smart tag will cause the Properties tool window to be displayed with the ExecuteCode property highlighted.
8. Enter the value codeActivity1_CodeHandler for the ExecuteCode property and press Enter.
9. This will cause a new method or handler to be added to the code-beside class for the workflow. Visual Studio will automatically open the Workflow1.xoml.cs code file and display the new codeActivity1_CodeHandler method. Alternatively, you can switch from the design view to the code-beside for the workflow by double-clicking on the activity or by selecting the View Code menu item.
10. The code-beside class is a partial class that inherits from the SequentialWorkflowActivity base class. This code-beside class will have the same name as the workflow. You should have the following code in your code-beside class:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace HelloWorldWorkflow
public partial class Workflow1 : SequentialWorkflowActivity
private void codeActivity1_CodeHandler(object sender, EventArgs e)

11. Insert the following code in the codeActivity1_CodeHandler method to output the string “Hello, World!” to the console:

private void codeActivity1_CodeHandler(object sender, EventArgs e)
Console.WriteLine("Hello, World!");

12. Select the Build Build Solution menu command to compile and build your project. Verify that there are no compiler errors or warnings.

Task 3 – Run the new workflow with Debugging

For this exercise we are going to use the simple host in program.cs that comes with the project template that was selected. Alternatively, you could build your own workflow host application by using the workflow runtime APIs defined in the System.Workflow.Runtime namespace.

1. Open the Visual Studio workflow designer by double clicking on workflow1.xoml in the solution explorer.
2. Click on the codeActivity1 activity to select it and set a breakpoint on it.
3. To set the breakpoint right-click on the code1 activity and choose Breakpoint Insert Breakpoint.
4. You should now see a red circle to the left of the code1 activity.

5. Compile and run the solution under the Visual Studio debugger by pressing F5 (or selecting the Debug Start Debugging menu command).
6. The ConsoleTestHost will start a workflow instance and that instance will break in the debugger when it gets to the code activity. The yellow box indicates the activity that the debugger is stopped at
7. Choose Debug Step Into from the menu and the debugger will step into the start of the code1_CodeHandler method.
8. Choose Debug Step Into a couple of more times and you should see “Hello, World!” written out into the test host’s console window.
9. The workflow will now complete and the program finishes.

No comments: