简体   繁体   中英

How to pass an argument into a workflow activity in code?

I am using Windows Workflow Foundation 4.5.

I want to pass an argument into a WriteLine activity. Code as below:

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);
    }
}

But I get the following error at runtime:

 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. 

So what's the correct way to do it?

The name of the argument is "Text". This will work:

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM