SharePoint Workflow architecture (2) Event Processing Pipeline and sharepointworkflow

Source: Internet
Author: User

SharePoint Workflow architecture (2) Event Processing Pipeline and sharepointworkflow

According to Andy Li, I have read the best and most thorough article on SharePoint Workflow architecture. After reading his article, I learned about the working mechanism of SharePoint Workflow and how to locate the problem. Therefore, we hope to help Workflow developers.


This blog was contributed by Andy Li. He is an engineer in the SharePoint support team who handles problems. Original address. This Workflow series is contributed to the community to help you better understand the internal mechanism of Workflow runtime and how to interact with SharePoint.

This article is translated by SPFarmer.


The first two addresses:

Host Service: SPWinOeHostService

Combination of SharePoint and Workflow Runtime


Event Processing Pipeline)

Almost all workflows require some user interaction. For example, you may need to create some tasks in workflow and assign them to some users for approval. When they receive their tasks, they will open the site and submit their feedback. The feedback will be sent back to workflow and then proceed. After a user submits a task, many operations are performed in the background. We mentioned earlier that when a user submits a task, an event handler will respond to the event and pass the task changes to workflow. Generally, we call this process event transfer. In workflow runtime, this process is called data exchange. They mean something. In this section, we will talk about all the actions in this process.

Workflow Data Exchange Service)

The Workflow host process can communicate with workflow through the custom local communication service. These local communication services implement custom interfaces that define communication methods and events between workflow and the host process. Events are used to send data to workflow. Conversely, workflow uses methods to send data to the host process.

The icon below shows how the local communication service communicates with its host process. You can read Using LocalServices in Workflows for more information.


For example, SharePoint definesITaskServiceExchange task information in SharePoint and the workflow where the task is created.ITaskService. CreateTaskThe workflow instance is used to create a task item in the task list.ITaskService. OnTaskChangedEvents are used by SharePoint (host process) to launch "events" to the workflow instance.

A service class that implements these interfaces is required to complete the data exchange. For exampleMicrosoft. SharePoint. Workflow. SPWinOeTaskServicesImplementedITaskServiceInterface. This service class actually allows you to create tasks in the SharePoint list and process events when the events are transmitted to the host process.

The last thing is to mount the data exchange service to your workflow. This isHandleExternalEventActivityAndCallExternalMethodActivityHow to participate in this matter. In SharePointCreateTaskEssentially, an activity is boundITaskService. CreateTaskCallExternalMethodActivity on.

ITaskService

Check it with ILSpyITaskServiceDefinition:


Now let's explain how correlation works. In short, the correlation parameter is used by workflow runtime to find the correct transfer target for the event. You may still remember that in SharePoint, every task activity requires the TaskId parameter (view the above ). Note. CreateTask has a CorrelationInitialization method, that is, to create a new TaskId in this method, which is used by other activities of this task, for example,OnTaskChangedActivity. Then, when a user submits a change to this task, workflow runtime uses this TaskId to findOnTaskChangedActivity, which is the place where the event should be passed (remember that there may be multiple workflow instancesOnTaskChangedActivities in the system ).

How does Correlation work?

CorrelationParameterAttributeDefines the identifier (Identifier)Every method or event on the. interface is a parameter, for exampleITaskServiceTaskId displayed in the interface Example. You can also use other attributes to describe more complex correlation matching.

Any operation that enables a session must have methods or eventsCorrelationInitializerAttributeProperties, for example,ITaskService. CreateTaskAndITaskService. CreateTaskWithContentTypeThe beginning of the session. WhenCorrelationInitializerAttributeWhen the attribute method is used, the service class knows that this call starts with a new session. The life time of a workflow session is dominated by the life time of the correlation reference.

The following shows the attributes of CreateTask Activity in Visual Studio. Note that we have bound the TaskId attribute to the taskdetailtaskid1 attribute of this class. In MethodInvoking(CreateTask1_Invoking (), we use a new GUID to initializeTaskId.

 

Do not confuse correlation parameter with "CorrelationToken". In the above, we noticed that the value of CorrelationToken is "taskToken". In the same workflowOnTaskChangedActivity (not shown here) uses the same correlation token, which means they are the same session.

Once the "taskId" isCreateTaskOrCreateTaskWithContentTypeWhen the activity is initialized, it will be shared by the task activity with the same correlationToken. In this way, they will know the task event. Then, when the listener arrivesITaskService. OnTaskChangedEventOnTaskChangedActivity, it registers an event on workflow runtime. Then, when workflow runtime is accepted from the host process (SharePoint process, w3wp or owstimer)OnTaskChangedDuring the event, she checks the taskId value of EventArgs and forwards the event toOnTaskChangedActivity.


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.