使用WorkflowApplication加载持久化的工作流实例 [英] Loading persisted workflow instances with WorkflowApplication

查看:53
本文介绍了使用WorkflowApplication加载持久化的工作流实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可能做错了.我在http://social.msdn.microsoft.com/Forums/en-CA/wfprerelease/thread/a11eb75d-65de-4787-9745-2fd634d0eee9中阅读了该主题,但我还是不明白.

I understand I may be doing this wrong.  I read the topic at http://social.msdn.microsoft.com/Forums/en-CA/wfprerelease/thread/a11eb75d-65de-4787-9745-2fd634d0eee9 but I still don't get it, exactly.

我有一个使用WorkflowApplications处理工作流的应用程序.我的工作流程包含一分钟的延迟"活动.击中该活动后,工作流将闲置,保留(SqlWorkflowDataStore)并卸载.一切都很好.如果该应用运行了几分钟,它将恢复并完成.

I have an application that uses WorkflowApplications to handle the workflows.  I have a workflow that contains a one minute Delay activity.  When this activity is hit, the workflow Idles, persists (SqlWorkflowDataStore), and unloads.  This is all fine.  If the app runs for the minute, it will be resumed and will complete.

但是,如果我在延迟的那一刻停止了该应用程序,然后在某个时候再次启动它,则工作流将无法恢复.稍加挖掘就会发现WorkflowApplication不会自动恢复,而我必须手动执行该操作.很好.问题是,我不知道如何.

However, if I stop the app during the minute that it is delayed, and then start it up again at some point later, the workflows do not resume.  A little digging shows that WorkflowApplication does not resume automatically, and that I have to do that manually.  That's fine.  The problem is, I don't know how.

我看到有一个WorkflowApplication.LoadRunnableInstance,并且在数据库中看到RunnableInstancesTable表中有记录.但是当我打电话给LRI时,我会得到以下提示:

I see there is a WorkflowApplication.LoadRunnableInstance, and I see in the db that there are records in the RunnableInstancesTable table.  But when I call LRI, I get back this:

未处理System.Runtime.DurableInstancing.InstancePersistenceCommandException
  Message =为了匹配并在商店中加载可运行实例,请求的InstanceOwner在创建时必须已指定工作流主机类型.为此,请在发出命令时将键值对添加到CreateWorkflowOwnerCommand.InstanceOwnerMetadata属性包中.密钥是文档中提供的WorkflowHostType密钥.该值必须是XName,并且与要加载的实例的XName相匹配.
  Source = System.Runtime.DurableInstancing
  StackTrace:
     在System.Runtime.AsyncResult.End [TAsyncResult](IAsyncResult结果)处
      在System.Runtime.DurableInstancing.InstancePersistenceContext.OuterExecute处(InstanceHandle initialInstanceHandle,InstancePersistenceCommand命令,事务事务,TimeSpan超时)
在System.Runtime.DurableInstancing.InstanceStore.Execute处(InstanceHandle句柄,InstancePersistenceCommand命令,TimeSpan超时)
在System.Activities.WorkflowApplication.PersistenceManager.TryLoad(TimeSpan超时,IDictionary`2&数据)中
     在System.Activities.WorkflowApplication.LoadCore(TimeSpan超时,布尔值loadAny)处
      在System.Activities.WorkflowApplication.LoadRunnableInstance(TimeSpan超时)处
      在D:\ lab \ WF4Sandbox \ Program.cs:第104行的WF4Sandbox.Program.LoadRunnable(活动活动)处
在D:\ lab \ WF4Sandbox \ Program.cs:line 70的WF4Sandbox.Program.Main(String [] args)处
在System.AppDomain._nExecuteAssembly(运行时程序集程序集,String [] args)处
       at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)
      在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()处
      在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)处
      在System.Threading.ExecutionContext.Run(执行ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值ignoreSyncCtx)处
在System.Threading.ExecutionContext.Run(执行ExecutionContext执行上下文,ContextCallback回调,对象状态)时
      在System.Threading.ThreadHelper.ThreadStart()处
  InnerException:

System.Runtime.DurableInstancing.InstancePersistenceCommandException was unhandled
  Message=In order to match and load a runnable instance in the store, the requesting InstanceOwner must have specified a workflow host type when it was created. To do so, add a key-value pair to the CreateWorkflowOwnerCommand.InstanceOwnerMetadata property bag when issuing the command. The key is the WorkflowHostType key provided in the documentation. The value must be an XName and match that of the instances being loaded.
  Source=System.Runtime.DurableInstancing
  StackTrace:
       at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.Runtime.DurableInstancing.InstancePersistenceContext.OuterExecute(InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, Transaction transaction, TimeSpan timeout)
       at System.Runtime.DurableInstancing.InstanceStore.Execute(InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout)
       at System.Activities.WorkflowApplication.PersistenceManager.TryLoad(TimeSpan timeout, IDictionary`2& data)
       at System.Activities.WorkflowApplication.LoadCore(TimeSpan timeout, Boolean loadAny)
       at System.Activities.WorkflowApplication.LoadRunnableInstance(TimeSpan timeout)
       at WF4Sandbox.Program.LoadRunnable(Activity activity) in D:\lab\WF4Sandbox\Program.cs:line 104
       at WF4Sandbox.Program.Main(String[] args) in D:\lab\WF4Sandbox\Program.cs:line 70
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

尽管冗长,但没有什么帮助,因为根本没有关于此主题的文档.使用Reflector来浏览程序集时,我可以在创建实例所有者时使用以下代码来绕过此消息:

Which, while verbose, is less than helpful, as there's no documentation on this subject at all.  Digging through the assemblies with Reflector, I can bypass this message by using the following code when creating my instance owner:

           InstanceHandle手柄= _store.CreateInstanceHandle(null);
            CreateWorkflowOwnerCommand cmd = new CreateWorkflowOwnerCommand();
            XNamespace hostNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities/4.0/properties");
            XName hostKey = hostNamespace.GetName("WorkflowHostType");
            InstanceValue hostValue =新的InstanceValue(XNamespace.Get("http://tempuri.org").GetName("Sentinel")));
        cmd.InstanceOwnerMetadata.Add(hostKey,hostValue);
            InstanceOwner owner = _store.Execute(handle,cmd,TimeSpan.MaxValue).InstanceOwner;
            _store.DefaultInstanceOwner =所有者;

            InstanceHandle handle = _store.CreateInstanceHandle(null);
            CreateWorkflowOwnerCommand cmd = new CreateWorkflowOwnerCommand();
            XNamespace hostNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities/4.0/properties");
            XName hostKey = hostNamespace.GetName("WorkflowHostType");
            InstanceValue hostValue = new InstanceValue(XNamespace.Get("http://tempuri.org").GetName("Sentinel"));
            cmd.InstanceOwnerMetadata.Add(hostKey, hostValue);
            InstanceOwner owner = _store.Execute(handle, cmd, TimeSpan.MaxValue).InstanceOwner;
            _store.DefaultInstanceOwner = owner;

但是,不仅在很多级别上感觉不正确,而且它也不起作用-我没有收到错误,但任何实例都没有加载.所以我的问题是,使用WorkflowApplication,如何恢复延迟的工作流?

But not only does that not feel right on so many levels, it also doesn't work -- I don't get the error, but neither do any of the instances load.  So my question is, using a WorkflowApplication, how do I resume a delayed workflow?

推荐答案

科林,

问题可能出在主机应用程序停止时您用来卸载工作流应用程序的方式.我认为您遇到了错误,因为工作流没有卸载.

The problem could be in the way you use to unload your workflowapplication when the host application is stopped. I think you have your bug because the workflow isn't unload.

在应用出口处,您是否通过工作流应用的卸载方法发送卸载请求?

At the applciation eexit you send unload request via Unload method of workflowapplciations?

http://msdn.microsoft. com/en-us/library/system.activities.workflowapplication.unloaded(v = VS.100).aspx

如果不这样做,则必须这样做;).

If you don't, you have to do it ;).

这将卸载数据库中工作流存储上的所有sql锁定.

That will unload all sql lock on workflow store in database.


这篇关于使用WorkflowApplication加载持久化的工作流实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆