views:

315

answers:

2

I have a .net 4.0 Workflow, which I am hosting myself (just with WorkflowInstance.Run) and when I rehydrate the workflow I would like to initialize some of its internal arguments so that subsequent activities can use these values... How might I go about doing this?

A: 

use Arguments (In/OutArgument) for defining input or output for the workflow (activities too)..

here is the sample syntax..

Dictionary <string, object> input = new Dictionary <string, object> (); 
input.Add( "UserName" , userName); 
input.Add ( "UserName", userName); 
WorkflowInstance myInstance = new WorkflowInstance(
new WorkflowConsoleApplication2.Sequence1(),input); 

WorkflowInstance myInstance = new WorkflowInstance (
new WorkflowConsoleApplication2.Sequence1 (), input);

in your workflow map, define the input argument and then you will be able to access the value of argument.

Jeeva S
But this cant be used when I am loading an _existing_ workflow can it?I would be using:WorkflowInstance.Load(WorkflowElement, PersistenceProvider)..there is no override that takes an argument dictionary.My requirement is that I dont have all the arguments until after the workflow has progressed to some point... then I can inject them for the following activities to use...
Adam
A: 

Normally Arguments are for providing to your workflow before you start executing the workflow the first time.

For example, you might have InArgument input1, InArgument input2, OutArugment output, and when you create the workflow you pass in all the inputs, and a variable for the workflow to store all of the outputs in.

Once the workflow is already running, it has arguments, it's not expecting them to change from some external factor. (And in case this is a point of confusion: it's not normally going to resume execution at the start of your workflow either - it's going to resume at some arbitrary bookmark in the middle.) So how else could you pass data in to your workflow in mid execution?

Here I suggest look at the messaging activities. Data comes 'in' to the workflow on the Value OutArgument of ReceiveMessage. How did it get there? It was set by the Receive activity. But how did the receive activity get it to set it? Well, first the service host tells the receive activity to resume because it has a message. Then the receive activity says 'what message did I get?' Nobody magically pushed data into it, instead after the activity is activated, it knows to pull data from a queue somewhere.

Hopefully you could use this idea of 1) someone stores the data needed by the workflow 2) the runtime or the service host or whatever reactivates the workflow 3) activities pull in the data they need when they run (after reactivation) as a model for your solution.

Tim Lovell-Smith