WF Series 3-CallExternalMethod Activity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.