【问题标题】:How to pass an argument into a workflow activity in code?如何将参数传递给代码中的工作流活动?
【发布时间】:2013-08-27 14:18:02
【问题描述】:

我使用的是 Windows Workflow Foundation 4.5。

我想将参数传递给 WriteLine 活动。代码如下:

class Program
{
    static void Main(string[] args)
    {
        WriteLine wf1 = new WriteLine();
        wf1.Text = "arg1";

        Dictionary<String, Object> arg = new Dictionary<String, Object>();
        arg.Add("arg1", "Hello,world!");

        WorkflowInvoker.Invoke(wf1, arg);
    }
}

但我在运行时收到以下错误:

Unhandled Exception: System.ArgumentException: The values provided for the root activity's arguments
 did not satisfy the root activity's requirements:
'WriteLine': The following keys from the input dictionary do not map to arguments and must be remove
d: arg1.  Please note that argument names are case sensitive.

那么正确的做法是什么?

【问题讨论】:

    标签: workflow workflow-foundation-4


    【解决方案1】:

    参数的名称是“文本”。这将起作用:

    class Program
    {
        static void Main(string[] args)
        {
            WriteLine wf1 = new WriteLine();
    
            Dictionary<String, Object> arg = new Dictionary<String, Object>();
            arg.Add("Text", "Hello,world!");
    
            WorkflowInvoker.Invoke(wf1, arg);
        }
    }
    

    【讨论】:

    • 现在我明白了为什么输入参数的类型是 DictionaryObject >。这样,我可以将任何类型传递到工作流中,并映射到其公共属性的名称。
    猜你喜欢
    • 1970-01-01
    • 2021-06-13
    • 2014-10-30
    • 2022-06-10
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多