Designing and coding

Menu

WF4: Passing In/OUT parameters

Today, I am going to share one more finding that I explored in last few days. It took my ample amount of time and at last found some solution.

So here, I was working on Workflow foundation4 and was passing arguments to it through designer. A lot of major changes made in WF4, which requires to learn lots of things. here I would be concentrating on passing arguments and few more things.

So I have created a workflow (Also called as activity) and created few In Arguments and Out Arguments. You can see about this in details here.

So I have created a sample workflow that takes few In Argument and Out arguments some of Int type and some string type. So while invoking the workflow I need to pass these parameter.

So I have created a workflow HelloFriend.xaml and which takes name as string and age as int of the as In parameter and return a WelcomeMessage of string type.
Now let’s see the code which invoke it.

As you can see workflow takes the inputs in Dictionary format and returns the output also in Dictionary format. As you can see I am passing name and age in it.
But Now let’s try to pass some arguments of custom type.
I have created two Classes one RequestType and Other ResponseType in a separate library. RequestType is as

Now I have added the reference to my workflow project. As worklow4 allows us to pass parameters of any custom type, I added a two parameters on In request and another response of RequestType and ResponseType respectively. Now I tried to invoke this workflow as

But I got this runtime error on the line where workflow is invoked:Literal’: Literal only supports value types and the immutable type System.String.
I tried to search the solution internet but could not find easily. Later I found the solution and I got to know if we want to pass some custom type then I need to pass it in as a lambda value. Then I converted the code as

It started running like a charm.
It means we cannot pass a custom type In arguments by just assigning the passing the object.We need to assign it as lambda format.
Sometimes we load the workflows dynamically. And these can be loaded as