How to assign a variable in a workflow if InvokeMethod activity returns an object?

688 views Asked by At

I have an InvokeMethod Activity in Windows Workflow Foundation. This workflow is quite simple:

  1. ask to user for his/her height
  2. if height is greater than 5.9, then ask his/her profile details
  3. display profile details

To achieve this, I have created a workflow, seen below: enter image description here

How can I assign an object which is return from InvokeMethod as variable?

I have posted my code on GitHub.

1

There are 1 answers

0
Nicolas P On

Here is the solution within Visual Studio properties:

First add a variable to your workflow:

Printscreen workflow's variables

Drop an InvokeMethod Activity into your workflow workspace and edit properties:

PrintScreen (Properties of InvokeMethod)

  1. MethodName: Enter your MethodName
  2. Parameters: Set parameters (Direction: In, Type: typeNeeded, Value yourValue)
  3. Result: Enter the variable name from your workflow defined earlier
  4. TargetType: Set the type of your method return's type

Here is the solution in XAMLX

xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"

<p1:InvokeMethod sap2010:WorkflowViewState.IdRef="InvokeMethod_1" MethodName="YourMethodName" TargetType="x:Object">
    <p1:InvokeMethod.Result>
        <p1:OutArgument x:TypeArguments="x:Object">
            <mca:CSharpReference x:TypeArguments="x:Object">workflowVariableName</mca:CSharpReference>
        </p1:OutArgument>
    </p1:InvokeMethod.Result>
    <p1:InArgument x:TypeArguments="x:Int32">
        <mca:CSharpValue x:TypeArguments="x:Int32">variableNamePassedToMyMethod;</mca:CSharpValue>
    </p1:InArgument>
</p1:InvokeMethod>