다음을 통해 공유


WF 4.0: Building a Hello World Sequential Workflow

WF 4.0: Building a Hello World Sequential Workflow

WF 4.0 Hello World Sequential Workflow

Note: This post is based on Visual Studio 2010 Beta 1 which is the latest version available in the time of writing this post, so by the time this technology ships, there are probably things that will be slight different.

Start Visual Studio 2010 Beta 1 and create a new Sequential Workflow Console Application.

WF 4.0 Hello World Sequential Workflow

After you click OK, visual studio creates the new projects and creates a new WF project, in which there are some things you should know about:

WF 4.0 Hello World Sequential WorkflowReferences:

  • System.Xaml – Now that there are several technologies based on Xaml, this is a new Assembly in .Net Framework 4.0 that contains Xaml services such as serialization.
  • System.Activities is the assembly that contains the implementation of WF 4.0, and as you can guess, the corresponding namespace is System.Activities and anything beneath it.
  • System.Activities.Design contains the designers for the activities and the designer re-hosting implementation. Since the new designer is based on WPF, you can also note references to WindowsBase, PresentationCode and PresentationFramework.
  • System.ServiceModel contains WCF implementation (as of .Net Framework 3.0) and now System.ServiceModel.Activities contains the activities used for Workflow Services (the integration between WF and WCF).

Sequence.xaml:

By default, workflows are created declaratively in WF 4.0 and represented in .xaml files with no code behind. If you open this file with an Xml editor, you will see it clearly.

<?xml version="1.0" encoding="utf-8" ?>

<p:Activity x:Class="HelloWorld.Sequence1"

          xmlns:p="https://schemas.microsoft.com/netfx/2009/xaml/activities"

          xmlns:s="clr-namespace:System;assembly=mscorlib"

          xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

          xmlns:sadx="clr-namespace:System.Activities.Design.Xaml;assembly=System.Activities.Design"

          xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">

    <p:Sequence sad:XamlDebuggerXmlReader.FileName="C:\...\HelloWorld\Sequence1.xaml">

 

    </p:Sequence>

</p:Activity>

The new WF Designer shows an empty sequence, representing an empty block of execution. Note the warning sign that says that the sequence has no child activities.

WF 4.0 Hello World Sequential Workflow

From the Procedural section in the Toolbox, drag the WriteLine Activity to the design surface.

WF 4.0 Hello World Sequential Workflow

Now, you get a warning that the Text property is not set. To set it, go the properties window, and open the Expression Editor. In WF 4.0 you use the Expression to set values to variables and parameters, and you can use either static values (like in this case) or VB. Yes! Expression are written in VB.

Type the text you want to display to the console and click OK.

WF 4.0 Hello World Sequential Workflow

Now, that the simple workflow is completed, you can use Ctrl + F5 to run it like you normally do.

WF 4.0 Hello World Sequential Workflow

Debugging a Workflow

The debugging experience when debugging a workflow in WF 4.0 is very similar to the debugging experience when using code. You can right click an activity the in designer and select Insert Breakpoint, or use F9 to do this.

WF 4.0 Hello World Sequential Workflow

Once you do this and run the workflow, the debugger highlights the current activity using a yellow border (similar to the yellow background for the current statement when debugging code).

WF 4.0 Hello World Sequential Workflow

Enjoy!

Comments