官术网_书友最值得收藏!

Creating a WF program using InOutArgument

In this task, we will create a WF program using InOutArgument. This type of argument is used to receive values and is also used to pass values out to the caller (WF host).

How to do it…

  1. Create a workflow project:

    Create a new Workflow Console Application under the Chapter01 solution and name the project as UseInOutArgument.

  2. Author a workflow:

    Create an InOutArgument type argument: InOutMessage. Author a WF program as shown in the following screenshot. In the Assign activity textbox, type InOutMessage = "Now, I am an OutMessage".

    How to do it…
  3. Write code to host the workflow:

    Open the Program.cs file and alter the code as shown:

    using System;
    using System.Activities;
    using System.Activities.Statements;
    using System.Collections.Generic;
    
    namespace UseInOutArgument{
        class Program{
            static void Main(string[] args){
                IDictionary<string, object> input =
                    new Dictionary<string, object>() 
                { 
                    {"InOutMessage","Now, I am InMessage"}
                };
                IDictionary<string,object> output=
                    WorkflowInvoker.Invoke(new Workflow1(),input);
                Console.WriteLine(output["InOutMessage"]);
            }
        }
    }
    
  4. Run it:

    Set UseInOutArgument as Startup project. 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 following screenshot:

How to do it…

How it works...

The following code block initializes the InArgument value:

IDictionary<string, object> input =
                new Dictionary<string, object>() 
            { 
                {"InOutMessage","Now, I am InMessage"}
            };

This statement will run the workflow program with the input dictionary.

IDictionary<string,object> output=
                WorkflowInvoker.Invoke(new Workflow1(),input);

The string Now, I am InMessage is printed by the workflow. The string Now, I am an OutMessage is a message altered in the workflow and passed to the host and then printed by the host program.

There's more...

We cannot assign a string to InOutArgument directly, and the following style of parameter initialization is not allowed:

IDictionary<string, object> output =
    WorkflowInvoker.Invoke(new Workflow1() 
    { 
        InOutMessage="Now,I am InMessage"
    });

See Also

  • Creating a WF program using OutArgument
  • Initializing a WF program using InArguments
主站蜘蛛池模板: 布拖县| 布拖县| 讷河市| 文水县| 湘乡市| 横山县| 石台县| 八宿县| 阿尔山市| 绥江县| 建昌县| 泉州市| 临沭县| 务川| 敦化市| 扶余县| 曲沃县| 迁安市| 三河市| 达拉特旗| 西乌珠穆沁旗| 南川市| 潞城市| 滦平县| 商洛市| 桐梓县| 莱阳市| 珲春市| 丹阳市| 海兴县| 金沙县| 龙泉市| 正定县| 澄迈县| 泰兴市| 攀枝花市| 兰溪市| 五家渠市| 邵武市| 平凉市| 陈巴尔虎旗|