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:
Invoke an instance method without parameters.
Invoke an instance method with two parameters (String and Int32).
Invoke an instance method with two parameters (String and Int32) and a parameter array of type String[].
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.
Invoke a static method with two parameters of type String and Int32.
Invoke an instance method with one generic parameter of type String.
Invoke a static method with two generic parameters of type String and Int32.
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.Invoke an asynchronous instance method.
Invoke two different methods on the same instance of an object using two InvokeMethod activities.
Store a value in an instance of an object.
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
Using Visual Studio 2010, open the InvokeMethodUsage.sln solution file in the CodedWorkflow\CS folder.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press CTRL+F5.
To run the designer workflow sample
Using Visual Studio 2010, open the InvokeMethodUsage.sln solution file in the DesignerWorkflow\CS folder.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press CTRL+F5.
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
|