In this task, we will create a WF program that can return a result to the workflow host.
Create a new Workflow Console Application under the
Chapter01solution; name the project as
Author a workflow:
Author the workflow shown in the following screenshot. Here are the detailed actions:
Sequenceactivity from Toolbox to the designer panel.
In the bottom of the designer panel, click the Arguments button, and click Create Argument to create an
WriteLineactivities from Toolbox into the
Sequenceactivity and fill the textboxes with "Start…" and "End" respectively.
Assignactivity from Toolbox to the designer panel. Fill the right expression box with
OutMessage, whereas fill the right expression box with the following string: This is a message from workflow.
Write code to host the workflow:
Program.csfile and change the host code as follows:
Startupproject. Press Ctrl+F5 to build and run the workflow without debugging. The application should run in a console window and print the message as shown in the next screenshot:
IDictionary<string,object> output= WorkflowInvoker.Invoke(new Workflow1()); Console.WriteLine(output["OutMessage"]);
There is a third type of workflow argument:
InOutArgument. It is a binding terminal that represents the flow of data into and out of an activity. In most cases, we can use
InOutArgument instead of
OutArgument. But there are still some differences—for example, we cannot assign a string to
InOutArgument, while it is allowed to assign a string to
directly in the host program.