SharePoint 工作流基础知识SharePoint workflow fundamentals

提供了 SharePoint 中的工作流基础结构的高级概述,包括平台体系结构和工作流互操作性桥的视图。Provides a high-level overview of the workflow infrastructure in SharePoint, including a view of the platform architecture and the workflow interop bridge.

备注

自 2020 年 8 月 1 日起,SharePoint 2010 工作流已对新租户停用,并于 2020 年 11 月 1 日从现有租户中删除。SharePoint 2010 workflows have been retired since August 1, 2020 for new tenants and removed from existing tenants on November 1, 2020. 如果你使用的是 SharePoint 2010 工作流,我们建议迁移到 Power Automate 或其他支持的解决方案。If you’re using SharePoint 2010 workflows, we recommend migrating to Power Automate or other supported solutions. 有关详细信息,请参阅 SharePoint 2010 工作流停用For more info, see SharePoint 2010 workflow retirement.

SharePoint 中的工作流概述Overview of workflows in SharePoint

SharePoint 工作流由 Windows Workflow Foundation 4 提供支持,它实际上是基于早期版本重新设计的版本。反过来说,Windows Workflow Foundation (WF) 是基于由 Windows Communication Foundation (WCF) 提供的消息功能构建的。SharePoint workflows are powered by Windows Workflow Foundation 4, which was substantially redesigned from earlier versions. Windows Workflow Foundation (WF), in turn, is built on the messaging functionality that is provided by Windows Communication Foundation (WCF).

从概念上说,工作流模型构成了业务流程。因此,Windows Workflow Foundation 4 工作流是工作流"活动"的结构化集合,其中每个工作流活动均表示业务流程的一个功能性组件。Conceptually, workflows model structured business processes. Therefore, Windows Workflow Foundation 4 workflows are a structured collection of workflow "activities," each of which represents a functional component of a business process.

SharePoint 中的工作流平台使用 Windows Workflow Foundation 4 活动模型表示基于 SharePoint 的业务流程。此外,SharePoint 引入了一个在其中创建工作流的更高级的阶段-关卡流程模型。The workflow platform in SharePoint uses the Windows Workflow Foundation 4 activity model to represent a SharePoint-based business process. Additionally, SharePoint introduces a higher-level stage-gate model on which to create workflows.

记下工作流 活动 与 SharePoint操作 之间的关系很重要。工作流活动表示其方法将推动工作流行为的基础托管对象。另一方面,工作流操作是一些包装,可封装基础活动并在 SharePoint Designer 中的用户友好表单中呈现它们。工作流作者与工作流操作进行交互,而工作流执行引擎将执行相应的活动。It is important to note the relationship between workflow activities and SharePointactions. Workflow activities represent the underlying managed objects whose methods drive workflow behaviors. Workflow actions, on the other hand, are wrappers that encapsulate the underlying activities and present them in a user-friendly form in SharePoint Designer. Workflow authors interact with the workflow actions, whereas the workflow execution engine acts on the corresponding activities.

作为活动类的实现的活动将通过使用 XAML 以声明方式实现。The activities, which are implementations of activity classes, are implemented declaratively by using XAML.

使用松散耦合的 Web 服务调用工作流活动,这些服务将使用消息 API 与 SharePoint 进行通信。这些 API 是基于由 Windows Communication Foundation (WCF) 提供的消息功能构建的。Workflow activities are invoked using loosely coupled web services that use messaging APIs to communicate with SharePoint. These APIs are built on the messaging functionality that is provided by Windows Communication Foundation (WCF).

消息框架非常灵活且支持您需要的几乎所有消息模式。请注意,在 SharePoint 场中,Windows Workflow Foundation 和 WCF 承载于 Workflow Manager Client 1.0 中。The messaging framework is very flexible and supports virtually any messaging pattern that you need. Note that on a SharePoint farm, Windows Workflow Foundation and WCF are hosted in Workflow Manager Client 1.0.

Workflow Manager Client 1.0、SharePoint 和 SharePoint Designer 2013 均提供了新的基础结构的重要部分:Workflow Manager Client 1.0, SharePoint, and SharePoint Designer 2013 each provide significant parts of the new infrastructure:

  • Workflow Manager Client 1.0 提供了工作流定义的管理。它还承载了工作流实例的执行过程。Workflow Manager Client 1.0 provides the management of workflow definitions. It also hosts the execution processes for workflow instances.

  • SharePoint 提供了针对 SharePoint 工作流的框架,该框架将为涉及 SharePoint 文档、列表、用户和任务的基于 SharePoint 的业务流程建模。此外,将在 SharePoint 中存储和管理 SharePoint 工作流、关联、活动和其他工作流元数据。SharePoint provides the framework for SharePoint workflows, which model SharePoint-based business processes that involve SharePoint documents, lists, users, and tasks. Additionally, SharePoint workflows, associations, activities, and other workflow metadata are stored and managed in SharePoint.

  • SharePoint Designer 2013 是用于创建并发布工作流定义的主业务用户工具,与早期版本一样。它还可用于打包带有或不带有关联的 SharePoint 组件的工作流定义。SharePoint Designer 2013 is the primary business-user tool for creating workflow definitions and publishing them, as it was in previous versions. It can also be used to package a workflow definition with or without associated SharePoint components.

平台体系结构Platform architecture

图 1 描述了 SharePoint 工作流框架的高级视图。首先,请注意新的工作流基础结构如何将 Workflow Manager Client 1.0 作为新的工作流执行主机引入。然而,在 SharePoint 自身承载的早期版本的工作流执行中,此情况已在 SharePoint 中发生改变。Workflow Manager Client 1.0 位于 SharePoint 外部并使用常见协议通过 Microsoft Azure 服务总线(由 OAuth 进行协调)进行通信。另外,SharePoint 包含您期望看到的功能:内容项、事件、应用程序等。但请注意,还会实现 SharePoint 2010 工作流主机(即 Windows Workflow Foundation 3 引擎)以实现向后兼容。可以在 使用 SharePoint 的工作流互操作中了解有关这一点的更多信息。Figure 1 depicts a high-level view of the SharePoint workflow framework. Notice, first, how the new workflow infrastructure introduces Workflow Manager Client 1.0 as the new workflow execution host. Whereas in previous versions workflow execution was hosted in SharePoint itself, this has changed in SharePoint. Workflow Manager Client 1.0 is external to SharePoint and communicates using common protocols over the Microsoft Azure service bus, mediated by OAuth. Otherwise, SharePoint includes the feature that you would expect to see: content items, events, apps, and so on. But notice that there is also an implementation of the SharePoint 2010 workflow host (that is, the Windows Workflow Foundation 3 engine) for backward compatibility. You can read more about this in Use workflow interop for SharePoint.

图 1. 工作流基础结构的高级体系结构Figure 1. High-level architecture of the workflow infrastructure

高级工作流体系结构

Workflow Manager Client 1.0在 SharePoint 中以 Workflow Manager Client 1.0服务应用程序代理的形式表示。此组件允许 SharePoint 与 Workflow Manager Client 1.0服务器进行通信和交互。同使用 OAuth 提供服务器间的身份验证。Workflow Manager Client 1.0 is represented in SharePoint in the form of the Workflow Manager Client 1.0 Service Application Proxy. This component allows SharePoint to communicate and interact with the Workflow Manager Client 1.0 server. Server-to-server authentication is provided using OAuth.

为其侦听工作流的 SharePoint 事件(如 itemCreateditemUpdated 等)将通过使用 Microsoft Azure 服务总线传送到 Workflow Manager Client 1.0。对于回程,平台将使用 SharePoint 代表性状态传输 (REST) API 回调到 SharePoint。SharePoint events for which a workflow is listening, like itemCreated , itemUpdated , and so on, are routed to Workflow Manager Client 1.0 using the Microsoft Azure service bus. For the return trip, the platform uses the SharePoint Representational State Transfer (REST) API to call back into SharePoint.

此外,还为 SharePoint 工作流对象模型增加了功能,这些功能统称为"工作流服务管理器",可使用该管理器管理和控制工作流及其执行。服务管理器的交互的主区域为部署、消息传送、实例控件和(用于向后兼容)与 SharePoint 2010 工作流的互操作性。There are also additions to the SharePoint workflow object model, called collectively the Workflow Services Manager, which allow you to manage and control your workflows and their execution. The primary zones of interaction for the services manager are deployment, messaging, instance control, and (for backward compatibility) interoperability with SharePoint 2010 workflows.

最后,提供了一个工作流创作组件。SharePoint Designer 现在可以创建和部署 SharePoint 2010 和 SharePoint 工作流。Visual Studio 2008 不仅可以提供用于创建声明性工作流的设计器图面,还可以创建与 Workflow Manager Client 1.0 功能完全集成的 SharePoint 外接程序 和解决方案。Finally, there is the workflow authoring component. SharePoint Designer can now create and deploy both SharePoint 2010 and SharePoint workflows. Visual Studio 2012 not only provides a designer surface for creating declarative workflows, but it can also create SharePoint Add-ins and solutions that fully integrate Workflow Manager Client 1.0 functionality.

工作流订阅和关联Workflow subscriptions and associations

由于对 SharePoint 工作流所做的最明显的更改是,将工作流处理移至诸如 Microsoft Azure 这样的外部工作流主机上,这对于将 SharePoint 消息和事件连接到 Microsoft Azure 中的工作流基础结构是至关重要的。此外,将基础结构连接到客户数据对于 Microsoft Azure 也是非常重要的。工作流关联(基于订阅的 WF 概念构建)是支持这些要求的 SharePoint 基础结构部分。Because the most significant change to SharePoint workflows is the moving of workflow processing onto external workflow hosts like Microsoft Azure, it was essential for SharePoint messages and events to connect to the workflow infrastructure in Microsoft Azure. In addition, it was necessary for Microsoft Azure to connect the infrastructure to customer data. Workflow associations (which are built on the WF concept of subscriptions) are the SharePoint infrastructure pieces that support these requirements.

Microsoft Azure 发布/订阅服务Microsoft Azure publication/subscribe service

您必须先查看 Microsoft Azure 发布/订阅服务(该服务有时称作"pub/sub"或简称为"PubSub",然后才能讨论工作流关联和订阅。PubSub 是一个异步消息框架。消息发送者(发布者)不会直接将消息发送给消息接收者(订阅者)。相反,发布者会将消息呈现为不知道消息订阅者的类。随后,订阅者通过根据其已创建的订阅标识感兴趣的消息来使用已发布的消息,而不管发布者的身份如何。Before you can discuss workflow associations and subscriptions, you must look at the Microsoft Azure publication/subscribe service, which is sometimes referred to as pub/sub, or simply PubSub. PubSub is an asynchronous messaging framework. Message senders (publishers) do not send messages directly to message receivers (subscribers). Instead, messages are rendered by publishers as classes that have no knowledge of the message subscribers. Subscribers, then, consume published messages by identifying messages of interest, regardless of the publisher, based on subscriptions that they have created.

通过将消息创建与消息使用分离可以实现可伸缩性和灵活性。它支持发布者端的多播消息,以及订阅者端的混杂消息使用。This decoupling of message creation from message consumption allows for scalability and flexibility. It enables multicast messaging on the publisher side, and for promiscuous message consumption on the subscriber side.

备注

PubSub 功能属于 Microsoft Azure 服务总线,为 WCF 和其他服务终结点提供连接选项。The PubSub feature is a part of the Microsoft Azure Service Bus, which provides connectivity options for WCF and other service endpoints. 其中包括 REST 终结点,它们位于网络地址转换 (NAT) 边界后面和/或绑定到经常变化的动态分配 IP 地址。These include REST endpoints, which can be located behind network address translation (NAT) boundaries, or bound to frequently changing, dynamically assigned IP addresses, or both. 若要详细了解 Azure 服务总线,请参阅服务总线For more information about the Azure Service Bus, see Service Bus.

工作流关联和关联范围Workflow associations and association scope

工作流关联使用特定的默认值将工作流定义绑定到特定的 SharePoint 范围。关联本身表示一组存储在 Azure 发布/订阅服务中的订阅规则,这些规则将处理传入消息以确保它们由适当的(即订阅的)工作流实例使用。Workflow associations bind workflow definitions to specific SharePoint scope, with specific default values. The associations themselves represent a set of subscription rules that are stored in the Azure publication/subscription service that process incoming messages to ensure that they are consumed by appropriate (that is, subscribed) workflow instances.

默认情况下,消息基础结构支持以下范围的工作流:By default, the messaging infrastructure supports workflows at the following scopes:

  • SPList (针对列表工作流)SPList (for list workflows)

  • SPWeb (针对网站工作流)SPWeb (for site workflows)

与早期版本不同,SharePoint 不支持范围限定为某个内容类型 ( SPContentType ) 的工作流。但由于消息基础结构是可扩展的,因此,它可以支持任意范围。作为一名开发人员,您可以将给定 WorkflowSubscription 实例的 EventSourceId 属性设置为任何 guid 。随后,您可以使用该 EventSourceId 值调用 PublishEvent(Guid, String, IDictionary<String, Object>) ,这将触发指定的 WorkflowSubscription 的新工作流实例。Unlike previous versions, SharePoint does not support workflows that are scoped to a content type ( SPContentType ). However, the messaging infrastructure is extensible, so it can support any arbitrary scope. As a developer, you can set the EventSourceId property on a given WorkflowSubscription instance to any guid. You can then use that EventSourceId value to call PublishEvent(Guid, String, IDictionary<String, Object>) , which triggers a new workflow instance of the specified WorkflowSubscription.

Microsoft Azure 中的工作流服务Workflow service in Microsoft Azure

SharePoint 工作流的关联由其在 Microsoft Azure 中的工作流服务表示。当一个应用程序必须获取工作流关联及其数据时,它必须先对给定范围内可用的所有工作流服务进行查询。Associations for SharePoint workflows are represented by their workflow service within Microsoft Azure. When an application has to acquire a workflow association and its data, it must first query for all of the workflow services that are available at a given scope.

同样地,工作流实例会将指针返回其各自的工作流服务。这就是确定其正确的关联的方式。Similarly, workflow instances carry a pointer back to their respective workflow service. This is the means by which its correct association is determined.

启动工作流Starting workflows

可以手动或自动启动工作流。Workflows can be started either manually or automatically.

手动工作流Manual workflows

当 PubSub 服务接收 StartWorkflow 消息时,将手动启动工作流。该消息包含以下说明性信息:Manual workflows are started when the PubSub service receives a StartWorkflow message. The message contains the following descriptive information:

  • 关联标识符(即 WorkflowSubscription 实例)。The association identifier (that is, the WorkflowSubscription instance).

  • 原始项上下文的 ID。它将与 PublishEvent 方法调用的 ItemId 参数和 EventSource 属性一起传入。The ID of the originating item context. This is passed in with the ItemId parameter and the EventSource property on the PublishEvent method call.

  • 手动启动的事件类型 ( WorkflowStart )。The event type for a manual start ( WorkflowStart ).

  • 来自订阅或 Init 表单(如果适当)的附加工作流初始参数。这将是 CorrelationId (对于订阅)和 WFInstanceId (对于 Init 表单)。Additional workflow initiation parameters, either from the subscription or from the Init form, as appropriate. This would be CorrelationId for the subscription and WFInstanceId for the Init form.

自动启动工作流Auto-start workflows

通过对 PubSub 服务使用 Add 消息启动自动启动工作流。该消息包含以下说明性信息:Auto-start workflows are initiated by using an Add message to the PubSub service. The message contains the following descriptive information:

  • 原始项上下文的 ID。The ID of the originating item context.

  • 此事件本身是一个常规 SharePoint Add 事件。The event itself is a normal SharePoint Add event.

  • 工作流启动参数The workflow initiation parameters.

备注

如果工作流自动对可重复事件(例如, OnItemChanged 事件)启动,那么在关联的工作流的现有运行实例完成运行前,不能启动给定关联的另一个工作流。If a workflow automatically starts on a repeatable event (for example, the OnItemChanged event), it cannot start another workflow of a given association until the existing running instance of the association's workflow has completed running.

工作流订阅Workflow subscriptions

订阅是对关联的自然补充,它允许工作流与关联进行交互。工作流必须使用 create 方法和 delete 方法在 Azure 服务总线上创建订阅。The natural complement to associations are subscriptions, which allow the workflow to interact with associations. The workflow must create subscriptions on the Azure Service Bus using create methods and delete methods.

用于创建订阅和实例化工作流的方法的签名指定可选参数和必需参数。The signatures of the methods that create the subscription and instantiate the workflow specify the parameters???both optional and required. 由于参数列表是由工作流作者确定,因此可能会因工作流定义而异。The list of parameters is determined by the workflow author, so they may differ from one workflow definition to another. 将订阅参数列表指定为工作流定义的元数据。The list of subscription parameters is specified as metadata of the workflow definitions. 订阅参数是在订阅创建时提供。The subscription parameters are provided when the subscription is created. 在 XAML 中将初始化参数列表指定为工作流定义的一部分。The list of initialization parameters is specified in XAML as part of the workflow definition. 初始化参数是在工作流实例化时提供。The initialization parameters are provided when the workflow is instantiated.

订阅绑定到特定 SharePoint 对象,可以是 SPList 实例,也可以是 SPWeb 实例。Subscriptions are bound to a specific SharePoint object???either an SPList instance or an SPWeb instance. 在订阅创建时,订阅对象类型以必需参数值的形式传入。The subscription object type is passed in as a value of a required parameter when the subscription is created. 对象类型定义了订阅范围,因此订阅只能响应已订阅对象上发生的事件。The object type defines the subscription scope so that a subscription can only respond to events that occur on the object to which they are subscribed.

SharePoint 工作流互操作SharePoint workflow interop

利用 SharePoint 工作流互操作性,可从 SharePoint 工作流(基于 Windows Workflow Foundation 4)中调用 SharePoint 2010 工作流(基于 Windows Workflow Foundation 3 构建)。从而实现在 2013 工作流内执行 2010 工作流。SharePoint workflow interop enables SharePoint 2010 workflows (which are built on Windows Workflow Foundation 3) to be called from SharePoint workflows, which are based on Windows Workflow Foundation 4. This allows you to execute 2010 workflows from within 2013 workflows.

这一点非常重要,因为您可能会将您要使用的 SharePoint 2010 与 SharePoint 工作流一起重复使用。此外,您可能希望使用 SharePoint 2010 中的活动或功能,而 SharePoint 中尚未实施这些活动或功能。This is important because you may have SharePoint 2010 that you may use to reuse in conjunction with your SharePoint workflows. Additionally, you may wish to use activities or features from SharePoint 2010, which are not yet implemented in SharePoint

有关 SharePoint 工作流互操作性的详细讨论,请参阅 使用 SharePoint 的工作流互操作For a full discussion of SharePoint workflow interop, see Use workflow interop for SharePoint.

另请参阅See also