Series Directory: WF Series 3 Out-of-the-Box Activities topic directory
3.2.1 CallExternalMethod Activity
CallExternalMethod Activity is an important component in the local communication service.
To use this Activity, you must set two attributes:
- InterfaceType: Specifies the interface used to define workflow communication.
- MethodName: Specifies the method to be called.
Citation:
Why is CallExternalMethod limited to methods that call known interfaces?
The reason is that the activity is not just a code performer, but a two-way communication with the local service is implemented together with the HandleExternalEvent activity. With the CallExternalMethod activity, you can call a service method to process events triggered by a service by adding HandleExternalEvent to a workflow.
Example:
1. Create a Sequential Workflow project
----- Drag CallExternalMethodActivity into Workflow
2. Create an interface File
3. Set the InterfaceType and MethodName attributes.
---- Set InterfaceType to InterfaceCode
---- Set MethodName to interfaceMethod
---- Print the predefined statement "invoke interfaceMethod"
* See, pay attention to this sentence: [Showing interfaces marked withExternalDataExchangeAttribute]
If [ExternalDataExchange] is not added to an Interface, no Interface is available.
Why should I add [ExternalDataExchange]?
It is necessary to declare the service interface. Otherwise, the service cannot be added to the process.
Private void callExternalMethodActivity1_MethodInvoking (object sender, EventArgs e)
{
Console. WriteLine ("execute CallExternalMethod Activity ");
}
The Main code is as follows:
Static void Main ()
{
Using (WorkflowRuntime workflowRuntime = new WorkflowRuntime ())
{
ExternalDataExchangeService dataService = new ExternalDataExchangeService ();
WorkflowRuntime. AddService (dataService );
DataService. AddService (new Serivces ());
WorkflowRuntime. StartRuntime ();
AutoResetEvent waitHandle = new AutoResetEvent (false );
WorkflowRuntime. WorkflowCompleted + = delegate (object sender, WorkflowCompletedEventArgs e) {waitHandle. Set ();};
WorkflowInstance instance = workflowRuntime. CreateWorkflow (typeof (DemoCallExternalMethodActivity ));
Instance. Start ();
WaitHandle. WaitOne ();
WorkflowRuntime. StopRuntime ();
}
}
Public class Serivces: InterfaceCode
{
InterfaceCode Members # region InterfaceCode Members
Public void interfaceMethod ()
{
Console. WriteLine ("invoke interfaceMethod ");
}
# Endregion
}
Someone also asked me: why do CallExternalMethodActivity and HandleExternalEventactivity often work together?
A: CallExternalMethodActivity is an execution action.
HandleExternalEventactivity is an event action
Therefore, the execution behavior usually triggers the event behavior. [Explanation of process ideas]
Attached with the CallExternalMethodActivity Application
Download DEMO