Basically this article gives an idea about how to pass the parameters and getting output parameters from the workflow.
Firstly let me discuss about the work flow basics. There are two important classes to understand for executing any workflow.
Workflow runtime: This class represents workflow runtime execution environment. We need to create an instance of work flow runtime engine to execute workflows. To execute any workflow first , we need to instantialte workflow runtime as below.
private WorkflowRuntime wfRunTime = new WorkflowRuntime();
Workflow instance: Represents a workflow instance by using the specified workflow
WorkflowInstance wi;
Once we have runtime environment for executing the workflow, we need to create new workflow instance as below. There are five overloaded methods to create workflow instance from workflow runtime class .one of the method, it takes Dictionary collection which defines the passing parameters to the work flow and getting output parameters values from the workflow.
In this example, 'params' is declared as dictionary collection and passed to the create workflow instance method.
var parms = new Dictionary<string, object>();
wi = wfRunTime.CreateWorkflow(typeof(WorkflowEx), parms);
wfRunTime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(wfRunTime_WorkflowCompleted);
The WorkflowCompletedEventArgs property of output parameters. We can retrieve the output parameters from the completed workflow.
Dictionary<string, object> OutputParameters { get; }
Workflow is added to solution.
In this example, sequential workflow class is added to run this example and named as workflowEx.
If else activity is added to the workflow and based on the user choice, the code will executed.

There are two code activities
- output welcome message from the workflow
- Giving sum and difference of the two numbers
All the properties i.e input parameters and output parameters will be declared in the workflow class
public partial class WorkflowEx : SequentialWorkflowActivity
{
private int _num1;
private int _num2;
private int _sum;
private int _diff;
private string _yourName;
private string _outputMessage;
private bool _choice =false;
public bool Choice
{
set { _choice =value; }
get {
return _choice;
}
}
public string OutputMessage
{
get { return _outputMessage; }
set
{
_outputMessage = value;
}
}
public string YourName
{
set { _yourName = value; }


Loris CabriniPosted May 5, 2010, 11:53 AM
great, thanks