简体   繁体   English

WF 4.5已标记为书签的自定义活动无法触发持久/卸载

[英]WF 4.5 Bookmarked custom activity not fire persist/unload

I've an application that host WF4.5 workflow in IIS using WorkflowServiceHost, WorkflowServiceHostFactory and WorkflowHostingEndpoint. 我有一个使用WorkflowServiceHost,WorkflowServiceHostFactory和WorkflowHostingEndpoint在IIS中托管WF4.5工作流的应用程序。

The workflow is defined by VS 2013 in a .xaml file. VS 2013在.xaml文件中定义了工作流。 In the workflow a have a custom activity for receive input data from a user. 在工作流中,有一个自定义活动,用于从用户接收输入数据。 Get that using CreateBookmark and the callback for Resume. 使用CreateBookmark和Resume的回调来获取该信息。

My problem is: The first activity execute and the workflow instance goes to idle, persist and unload. 我的问题是:执行第一个活动,工作流实例进入空闲,持久和卸载状态。 After resuming the first bookmark the second activity execute an the workflow instance goes to only idle. 恢复第一个书签后,第二个活动将执行,工作流实例将变为仅空闲状态。 Thus only the first activity make workflow instance to persist and unload. 因此,只有第一个活动才能使工作流实例得以持久和卸载。

To verify that my host implementation works, i used a Delay activity and everything works. 为了验证我的主机实现是否有效,我使用了一个Delay活动,并且一切正常。

My custom activity: 我的自定义活动:

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");

After a conclusion of a bookmarked activity(createbookmark/resume) the instance no more persist/unload. 完成书签活动(创建书签/恢复)后,该实例将不再持久/卸载。

In other words, only the first bookmarked activity set instance do unload. 换句话说,只有第一个加书签的活动集实例会卸载。 And yes , I've set TimeToPersist/TimeToUnload. 是的,我已经设置了TimeToPersist / TimeToUnload。

Here is the tracking status of the instance: Started, Idle, Persisted, Unloaded , Resumed, Idle, Idle, Idle, Idle, Idle, Completed, Deleted . 这是实例的跟踪状态:已启动, 空闲,持久,卸载 ,恢复,空闲,空闲,空闲,空闲,空闲,已完成,已删除

I created a sample solution that demonstrates the problem. 我创建了一个示例解决方案来演示该问题。 Sample for download. 下载样本。

I really appreciate if someone could help me. 如果有人可以帮助我,我非常感谢。 Thank you for any help! 感谢您的任何帮助!

Thank you for any help! 感谢您的任何帮助!

A workflow instance will persist at runtime only when it enters a persistable state, either when it goes idle or Persist activity is used. 工作流实例只有进入空闲状态或使用Persist活动时才进入运行时状态,才能在运行时保留。

WorkflowServiceHost doesn't give you much control over when workflow instance is persisted but you can configure the when . WorkflowServiceHost不能让您对何时保留工作流实例保持太多控制权,但是您可以配置when Check How to: Configure Idle Behavior with WorkflowServiceHost . 检查如何:使用WorkflowServiceHost配置空闲行为

Quoting: 报价:

Workflows go idle when they encounter a bookmark that must be resumed by some external stimulus, for example when the workflow instance is waiting for a message to be delivered using a Receive activity. 当工作流遇到必须由某些外部刺激来恢复的书签时,例如,当工作流实例正在等待使用Receive活动传递消息时,工作流将变为空闲状态。 WorkflowIdleBehavior is a behavior that allows you to specify the time between when a service instance goes idle and when the instance is persisted or unloaded. WorkflowIdleBehavior是一种行为,允许您指定服务实例进入空闲状态以及实例被持久保存或卸载之间的时间。 It contains two properties that enable you to set these time spans. 它包含两个属性,使您可以设置这些时间跨度。 TimeToPersist specifies the time span between when a workflow service instance goes idle and when the workflow service instance is persisted. TimeToPersist指定工作流服务实例进入空闲状态和持久化工作流服务实例之间的时间跨度。 TimeToUnload specifies the time span between when a workflow service instance goes idle and when the workflow service instance is unloaded, where unload means persisting the instance to the instance store and removing it from memory TimeToUnload指定从工作流服务实例变为空闲到卸载工作流服务实例之间的时间间隔,其中卸载表示将实例持久保存到实例存储并将其从内存中删除

<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <workflowIdle timeToUnload="0:05:0" timeToPersist="0:04:0"/> 
        </behavior>
    </serviceBehaviors>
</behaviors>

Note that the default value for timeToPersist is MaxValue . 请注意, timeToPersist默认值为MaxValue So, although your custom activity goes idle because you're creating a bookmark, it never persists (at least for a long!! time). 因此,尽管您的自定义活动由于正在创建书签而变得闲置,但它永远不会持续(至少很长一段时间!)。

EDIT: 编辑:

After playing with your sample and reading some documentation, what you need to do is to call SendResponse within OnResolveBookmark 玩完示例并阅读了一些文档之后,您需要在OnResolveBookmark中调用SendResponse

protected override Bookmark OnResolveBookmark(object[] inputs, OperationContext operationContext, WorkflowHostingResponseContext responseContext, out object value)
{
    Bookmark bookmark = null;
    value = null;
    if (operationContext.IncomingMessageHeaders.Action.EndsWith("ResumeBookmark"))
    {
        //bookmark name supplied by client as input to IWorkflowCreation.ResumeBookmark
        bookmark = new Bookmark((string)inputs[1]);
        //value supplied by client as argument to IWorkflowCreation.ResumeBookmark
        value = (string)inputs[2];

        // !!! Call it here, for example. !!!
        responseContext.SendResponse(null, null);
    }
    else
    {
        throw new NotImplementedException(operationContext.IncomingMessageHeaders.Action);
    }

    return bookmark;
}

This is briefly pointed out here : 这是简单地指出, 在这里

Override OnResolveBookmark to manually extract the bookmark from the incoming message. 覆盖OnResolveBookmark可以从传入消息中手动提取书签。 If you override this method, you must invoke SendResponse in its body so as to respond to the message sent to the WorkflowHostingEndpoint 如果重写此方法,则必须在其主体中调用SendResponse,以便响应发送给WorkflowHostingEndpoint的消息。

I don't known if this can be seen as a bug or not. 我不知道这是否可以视为错误。 The workflow engine seems to get into a state where, although it goes idle because you're giving it a bookmark, it doesn't really known it because a response warning about it is never sent. 工作流引擎似乎进入一种状态,尽管它由于您为它添加了书签而处于空闲状态,但由于从未发送过有关它的响应警告,因此它实际上并不清楚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM