Partilhar via


Hello World Custom Activity

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates several key features of Windows Workflow Foundation (WF), including how to create a simple custom activity. Some of the features demonstrated in this sample are creating a custom activity in C# and using in and out arguments (InArgument and OutArgument).

Ee624142.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\CustomActivities\Code-Bodied\HelloWorld

Creating a Workflow in Code

In this sample, two custom activities are created using C# code. Both custom activities inherit directly or indirectly from Activity to return a single value. The advantage of using the generic return value, instead of inheriting from the non-generic Activity class, is that some activities (such as Assign) are able to access the return value when used as part of a composed activity.

  • AppendString
    This activity inherits from Activity, and uses an Assign activity that concatenates two strings together.
  • Prepend String
    This activity inherits directly from CodeActivity, and creates similar functionality to the AppendString activity, which uses logic implemented in code rather than being composed of a pre-existing activity.

The following files are included in this project.

  • AppendString.cs
    The custom activity that appends strings together. It takes in a string and combines it with a literal text string “ says hello world” to form a complete message as output.
  • PrependString.cs
    This activity prefixes a predefined string to an input string.
  • Sequence1.xaml
    A workflow that uses the AppendString and PrependString custom activities.
  • Program.cs
    A program that runs the workflow.

To use this sample

  1. Using Visual Studio 2010, open the HelloWorld.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. To run the solution, press F5.