Export (0) Print
Expand All

Using the InvokeMethod Activity

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to use the InvokeMethod activity to invoke public methods in public classes. The InvokeMethod 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 InvokeMethod activity where the return value is returned through the 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.

To use this sample

  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.

Dd807388.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. 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

Community Additions

ADD
Show:
© 2014 Microsoft