《WF编程》系列- 承载工作流:持久化与跟踪

《WF编程》系列- 承载工作流:持久化与跟踪

SQL持久化和跟踪服务分别为工作流状态和跟踪信息提供了持久的存储。但是,它们并没有一起工作。具体来说,每个服务都会使用不同的数据库连接来进行操 作。工作流Runtime也因此会使用多个数据库连接。如果跟踪服务开启了事务支持,则会导致额外的开销出现。当事务跨越多个连接时,微软分布式事务协调 程序(Microsoft Distributed Transaction Coordinator,MSDTC)会接受事务的管理。MSDTC也会造成一些开销。WF为同时使用了SQL持久化和SQL跟踪服务的应用程序提供了优 化方案:SharedConnectionWorkflowCommitWorkBatchService类。这个服务允许两个SQL服务共享一个连接 (前提是这两个SQL服务的连接字符串是相同的)。

6.5.1 共享连接的配置

下面的配置文件配置了SQL工作流服务和共享连接服务。因为我们把连接字符串定义在了CommonParameters节中,所以所有的服务都会使用这个连接字符串。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<configSections>
  
<section name="WorkflowConfiguration"
  type
="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  
</configSections>
  
<WorkflowConfiguration>
  
<CommonParameters>
  
<add name="ConnectionString" value="Data Source=(local);Initial Catalog=WorkflowDB;Integrated Security=true"/>
  
</CommonParameters>
  
<Services>
  
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  UnloadOnIdle
="true" />
  
<add type= "System.Workflow.Runtime.Hosting.SharedConnectionWorkflowCommitWorkBatchService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  
</Services>
  
</WorkflowConfiguration>
</configuration>
我们不需要更改我们的应用程序,共享连接服务会在后台和其它Runtime服务一起协调。

6.6 小结

本章回顾了Windows Workflow Runtime的一些功能。我们分析了如何通过订阅Runtime事件和配置跟踪信息来监视工作流Runtime,还分析了如何通过添加服务来定制 Runtime。这些服务包括调度服务(用作管理线程)、持久化服务(用作管理状态)和跟踪服务(用作记录跟踪信息)。如果内置的服务并不能完全满足你的 需求,我们可以自己编写服务来替换掉它们。这中架构给予了Windows Workflow Runtime很大的灵活性和扩展性。

posted on 2010-11-30 22:42  Ben zhang  阅读(205)  评论(0编辑  收藏  举报

导航