Awarious OfficePortal - HRMS Application

How to pass data between the activities in workflow-foundation?

0 votes
asked Jul 11, 2013 in Workflow Foundation by Sanjay

I am not really understood, how to pass data between 2 activities in workflow foundation? What is the best way to do it? Is there any sample available for this? I am using .NET 4.0 with Visual Studio 2010. Any clarification or link to good article, I would appreciate.


1 Answer

+1 vote
answered Jul 12, 2013 by Aadhira (1,215 points)
selected Jul 12, 2013 by administrator
Best answer

Passing data between the workflow activities are very simple. It is same as passing value to regular C# functions. In windows workflow foundation you can send data using Arguments.

There are 3 kinds of arguments in WF

"InArguments" - which expect the parameter to come from outside.(Same as parameter pass by value in regular C# function)
"OutArguments" – Can be used to send the data back to the calling activity
"InOutArguments" like ByRef argument. Parameter will be passed to the activity from the previous activity. If there are any changes to that parameter, that will reflect outside the activity.

There is no constructor concept you need to use to pass these arguments to the activity. Instead, create public properties of type InArgument, OutArgument or InOutArgument

Custom CodeAcivity Sample

public sealed class GetEmployeeDetailActivity : CodeActivity
 // Define an activity input argument of type string
 public InArgument<string> EmpNumberArg { get; set; }
 public InArgument<IEmployeeRepository> EmployeeRepositoryArg { get; set; }
 public OutArgument<EmployeeDetail> EmployeeDetail { get; set; }
 // If your activity returns a value, derive from CodeActivity<TResult>
 // and return the value from the Execute method.
 protected override void Execute(CodeActivityContext context)
 // Obtain the runtime value of the Text input argument
 string empNumber = context.GetValue(EmpNumberArg);
 IEmployeeRepository employeeRepository = context.GetValue(EmployeeRepositoryArg);
 EmployeeDetail.Set(context, employeeRepository.GetEmployee(empNumber));

Once you create the properties, they will be visible in the property window of that particular activity. After than we can we can sent the value of that property using VB Expression window we have for each property. In that window, you can write code if you want to do any manipulation.

enter image description here

enter image description here
Passing InArgument and Reading OutArgument in workflow

Once you pass the value to the parameter, the value cannot be directly used inside the activity. Because, those properties of type InArgument or OutArgument.
To get the value inside that property, we need context object. We can get it using any one of the syntax.

EmpNumberArg.Get(context) //context is CodeActivityContext Or NativeActivityContext



In the given below image, I have explained the way to send values to the parameters in GetEmployeeDetailActivity, which is simple code activity.

SoftwareRequestWFContext argument passed from view model, has values for the EmployeeRepository and the Managers EmpNumber which has been passed as "In" arguments for GetEmployeeDetailActivity created as a Custom Activity to get employee detail if we pass the employee number using IEmployeeRepository

SoftwareRequestWFContext workflowContext = new SoftwareRequestWFContext()
    Employee = this.EmployeeDetail,
    SoftwareRequest = this.SoftwareRequest,
    EmployeeRepository = new EmployeeRepository(),
    SoftwareRequestRepository = new SoftwareRequestRepository()

GetEmployeeDetailActivity has an "Out" argument called "EmployeeDetail" which of type "EmployeeDetail". That OutArguments value has been assigned to a Variable "Manager" of type "EmployeeDetail" which is created in the scope of the FlowChart. So, once you assign the "Manager" variable in place of the OutArgument of GetEmployeeDetailActivity, then the value from that activity will be copied into Manager Variable. It is something like assignment operation. Then the Manager variable can be used in any other activities which are in that scope.

Your answer


Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2019