我有一个使用 WorkflowServiceHost、WorkflowServiceHostFactory 和 WorkflowHostingEndpoint 在 IIS 中托管 WF4.5 工作流的应用程序。
工作流由 VS 2013 在 .xaml 文件中定义。在工作流中,有一个自定义活动用于接收来自用户的输入数据。使用 CreateBookmark 和 Resume 的回调来获取它。
我的问题是:第一个活动执行,工作流实例进入空闲、持久和卸载。在恢复第一个书签后,第二个活动执行,工作流实例只进入空闲状态。因此只有第一个活动使工作流实例持久化和卸载。
为了验证我的主机实现是否有效,我使用了延迟活动并且一切正常。
我的自定义活动:
public sealed class WaitForResponse<TResult> : NativeActivity<TResult>
{
public string ResponseName { get; set; }
protected override bool CanInduceIdle
{
get
{
return true;
}
}
protected override void Execute(NativeActivityContext context)
{
context.CreateBookmark(this.ResponseName, new BookmarkCallback(this.ReceivedResponse));
}
protected void ReceivedResponse(NativeActivityContext context, Bookmark bookmark, object obj)
{
this.Result.Set(context, (TResult)obj);
}
}
IWorkflowCreation client = new ChannelFactory<IWorkflowCreation>(new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), new EndpointAddress("net.pipe://localhost/workflowCreationEndpoint")).CreateChannel();
//create an instance
Guid id = client.Create(null);
// Resume
client.ResumeBookmark(id, "1", "Message 1");
在书签活动(创建书签/恢复)结束后,实例不再持久/卸载。
换句话说,只有第一个加书签的活动集实例才会卸载。是的,我设置了 TimeToPersist/TimeToUnload。
下面是实例的跟踪状态: Started, Idle, Persisted, Unloaded , Resumed, Idle, Idle, Idle, Idle, Idle, Completed, Deleted。
我创建了一个示例解决方案来演示该问题。示例供下载。
如果有人可以帮助我,我真的很感激。感谢您的任何帮助!
感谢您的任何帮助!