Using the InvokeMethod Activity

.NET Framework (current version)
 

This sample demonstrates how to use the T:System.Activities.Statements.InvokeMethod`1 activity to invoke public methods in public classes. The T:System.Activities.Statements.InvokeMethod`1 activity allows a workflow to call methods against objects, pass in parameters, get the return value, specify types for generic methods, and specify whether the method is synchronous or asynchronous.

There is a non-generic version of the InvokeMethod activity where the return value is set to the Result property and a generic version of the T:System.Activities.Statements.InvokeMethod`1 activity where the return value is returned through the P:System.Activities.Statements.InvokeMethod.Result`1.Result property of type TResult.

This sample demonstrates how to call various method types. The following list details the method types demonstrated in this sample:

  • Invoke an instance method without parameters.

  • Invoke an instance method with two parameters (System.String and System.Int32).

  • Invoke an instance method with two parameters (System.String and System.Int32) and a parameter array of type System.String[].

  • Invoke an instance method with two parameters (two System.Int32 numbers) and a result of type System.Int32.

    The return value is bound to a variable and printed to the console using the WriteLine activity.

  • Invoke a static method with two parameters (System.String and System.Int32).

  • Invoke an instance method with one generic parameter (System.String).

  • Invoke a static method with two generic parameters (System.String and System.Int32).

  • Invoke an instance method that has one parameter passed by reference (System.String).

    The referenced parameter is bound to a variable and printed to the console using the WriteLine activity.

  • Invoke an asynchronous instance method.

  1. Using Visual Studio 2010, open the InvokeMethodUsage.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. To run the solution, press CTRL+F5.

System_CAPS_ICON_important.jpg Important

The samples may already be installed on your machine. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\Built-InActivities\InvokeMethod

Show: