WWF:SqlWorkflowInstanceStoreBehavior与SqlWorkflowInstanceStore

时间:2019-02-05 13:14:36

标签: c# workflow workflow-foundation-4 workflow-foundation sqlworkflowpersistencese

我有一个Windows服务,其中包装了WCF服务,该服务包含一个运行Activity的WorkflowApplication。我还配置了SQL Server 2008 Express(我知道它正在接近EOL,但文档明确指出仅支持SQL Server 2005或SQL Server 2008)来承载数据库和连接起作用。更清楚地说:Activity的整个过程完成并收到返回值(我通过包装在PowerShell中的WCF客户端调用它)。

我遇到的问题是,我已经在WorkflowApplication上的ServiceHost SqlWorkflowInstanceStore上配置了SqlWorkflowInstanceStoreBehavior。这些都不会引发SQL异常,但是我认为 ServiceHost占有优势,因为我所看到的只是LockOwnersTable上的一个单一条目。

Windows服务中的代码:

        this.obj = new ServiceHost(typeof(WorkflowService));
        SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior("Server=.\\SQL2008EXPRESS;Initial Catalog=WorkflowInstanceStore;Integrated Security=SSPI")
        {
            HostLockRenewalPeriod = TimeSpan.FromSeconds(5),
            InstanceCompletionAction = InstanceCompletionAction.DeleteNothing,
            InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry,
            InstanceEncodingOption = InstanceEncodingOption.GZip,
            RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(2)
        };
        this.obj.Description.Behaviors.Add(instanceStoreBehavior);
        this.obj.Open();

来自WCF服务/工作流应用程序的代码:

        SqlWorkflowInstanceStore newSqlWorkflowInstanceStore = new SqlWorkflowInstanceStore("Server=.\\SQL2008EXPRESS;Initial Catalog=WorkflowInstanceStore;Integrated Security=SSPI")
                                                        {
                                                            EnqueueRunCommands = true,
                                                            HostLockRenewalPeriod = TimeSpan.FromSeconds(5),
                                                            InstanceCompletionAction = InstanceCompletionAction.DeleteNothing,
                                                            InstanceLockedExceptionAction = InstanceLockedExceptionAction.BasicRetry,
                                                            RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(5)
                                                        };
        InstanceHandle workflowInstanceStoreHandle = newSqlWorkflowInstanceStore.CreateInstanceHandle();
        CreateWorkflowOwnerCommand createWorkflowOwnerCommand = new CreateWorkflowOwnerCommand();
        InstanceView newInstanceView = newSqlWorkflowInstanceStore.Execute(workflowInstanceStoreHandle, createWorkflowOwnerCommand, TimeSpan.FromSeconds(30));
        newSqlWorkflowInstanceStore.DefaultInstanceOwner = newInstanceView.InstanceOwner;

        // Now stage the WorkflowApplication, using the SQL instance.
        AutoResetEvent syncEvent = new AutoResetEvent(false);
        WorkflowApplication newWorkflowApplication = new WorkflowApplication(unwrappedActivity)
                                                         {
                                                             InstanceStore = newSqlWorkflowInstanceStore
                                                         };

问题:

  1. ServiceHost是否在WorkflowApplication上SqlWorkflowInstanceStoreBehavior 覆盖 SqlWorkflowInstanceStore?如果是这样,显而易见的答案是删除ServiceHost上的SqlWorkflowInstanceStoreBehavior;但是,如前所述,我担心这将徒劳无功,因为WorkflowApplication当前没有记录任何内容(甚至尝试记录,据我所知)。

  2. ASAppInstanceService似乎特定于WindowsServer。如果ServiceHost(通过Windows Service选项)始终 会阻止/禁用WorkflowApplication进行SQL调用,是否可以在Windows 10上托管这些(用于开发/预生产)? / p>

1 个答案:

答案 0 :(得分:0)

找出答案:

newWorkflowApplication.Persist();