InvokeMethod

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

This sample shows the different ways of using the InvokeMethod activity to invoke methods of a class.

A method belongs to a class and represents a contained set of operations. The InvokeMethod activity gives you the ability to call methods against objects or types, pass in parameters, and get the return value. Methods can be invoked synchronously or asynchronously.

Sample Details

This sample uses the InvokeMethod activity to perform the following scenarios:

  1. Invoke an instance method without parameters.

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

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

  4. Invoke an instance method with two parameters of type Int32 and a result of type Int32. In this scenario, the result value is bound to a variable and used in another activity. It is displayed in the console using the WriteLine activity.

  5. Invoke a static method with two parameters of type String and Int32.

  6. Invoke an instance method with one generic parameter of type String.

  7. Invoke a static method with two generic parameters of type String and Int32.

  8. Invoke an instance method that has one parameter passed by reference of type String. In this scenario, the reference parameter is bound to a variable (outParam) and used in another activity. It is displayed on the console using the WriteLine activity.

  9. Invoke an asynchronous instance method.

  10. Invoke two different methods on the same instance of an object using two InvokeMethod activities.

  11. Store a value in an instance of an object.

  12. Retrieve a value from an instance of an object.

To use this sample

This sample is provided in two versions. The first version of this sample demonstrates the usage of InvokeMethod through C# code using the Windows Workflow Foundation (WF) programming model and can be found under the CodedWorkflow\CS folder. The second version demonstrates the usage of InvokeMethod using XAML and can be found under the DesignerWorkflow\CS folder.

To run the coded workflow sample

  1. Using Visual Studio 2010, open the InvokeMethodUsage.sln solution file in the CodedWorkflow\CS folder.

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

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

To run the designer workflow sample

  1. Using Visual Studio 2010, open the InvokeMethodUsage.sln solution file in the DesignerWorkflow\CS folder.

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

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

Ee622976.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