WF 4.5书签自定义活动不火持续/卸载 [英] WF 4.5 Bookmarked custom activity not fire persist/unload

查看:317
本文介绍了WF 4.5书签自定义活动不火持续/卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在IIS主机WF4.5工作流程使用WorkflowServiceHost中,WorkflowServiceHostFactory和应用WorkflowHostingEndpoint。

工作流程是由VS 2013中的.xaml文件中定义。在工作​​流程中的具有用于从用户接收输入数据的自定义活性。获取,使用CreateBookmark和回调继续。

我的问题是:第一个活动执行和工作流实例进入空闲,坚持和卸载。恢复第一书签之后的第二个活动执行工作流实例前进到仅空闲。因此,只有在第一个活动让工作流实例坚持和卸载。

要验证我的主机都可以工作,我用一个延迟活动和一切正常。

我的自定义活动:

 公共密封类waitForResponse的< TResult> :NativeActivity的< TResult>
{
    公共字符串ResponseName {获得;组; }

    保护覆盖BOOL CanInduceIdle
    {
        得到
        {
            返回true;
        }
    }

    保护覆盖无效执行(NativeActivityContext上下文)
    {
        context.CreateBookmark(this.ResponseName,新BookmarkCallback(this.ReceivedResponse));
    }

    保护无效ReceivedResponse(NativeActivityContext情况下,收藏的书签,obj对象)
    {
        this.Result.Set(背景下,(TResult)目标文件);
    }
}

IWorkflowCreation客户=新的ChannelFactory&其中; IWorkflowCreation>(新NetNamedPipeBinding(NetNamedPipeSecurityMode.None),新的EndpointAddress(net.pipe://本地主机/ workflowCreationEndpoint))CreateChannel();

//创建一个实例
GUID ID = client.Create(空);

// 恢复
client.ResumeBookmark(ID,1,消息1);
 

一个书签的活动进行了总结(createbookmark /简历)后实例没有更多的坚持/卸载。

在换句话说,只有第一个书签的活动设置实例来卸载。是的,我给自己定TimeToPersist / TimeToUnload。

下面是实例的跟踪状态: 开始,空闲,坚持,卸载,重新开始,空闲,空闲,空闲,空闲,空闲,已完成,已删除的。

我创建了一个演示该问题的样品溶液。 样品下载。

我真的AP preciate如果有人可以帮助我。感谢您的帮助!

感谢您的帮助!

解决方案

一个工作流实例将坚持在运行时,只有当它进入一个持久化状态,或者当它空闲或的坚持活动使用。

WorkflowServiceHost中不会给你太多的控制时,工作流实例的持续存在,但你可以配置的的。检查如何:使用WorkflowServiceHost中。

报价:

  

工作流进入空闲状态,他们遇到必须恢复书签的时候   由一些外部刺激,例如,当工作流实例是   等待消息给使用接收活动递送。   WorkflowIdleBehavior是一种行为,它允许您指定的时间   当一个服务实例进入空闲状态,当实例之间   持续或卸载。它包含两个属性,使您可以   设置这些时间跨度。 TimeToPersist指定之间的时间跨度   当工作流服务实例进入空闲状态时的工作流程   服务实例仍然存在。 TimeToUnload指定的时间跨度   当工作流服务实例进入空闲状态时之间   工作流服务实例被卸载,卸载的地方意味着持续存在   该实例的实例存储,并从内存中取出

<行为>     < serviceBehaviors>         <行为NAME =>             &所述; workflowIdle timeToUnload =0:05:0timeToPersist =0:04:0/>         < /行为>     < / serviceBehaviors> < /行为>

请注意,对于timeToPersist中的默认值是MaxValue的的。所以,虽然你的自定义活动进入闲置状态,因为你要创建一个书签,它永远不会持续(至少在很长一段时间!)。

编辑:

玩你的样品和阅读一些文件后,你需要做的是叫<一href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.workflowhostingresponsecontext.sendresponse(v=vs.110).aspx"相对=nofollow> SendResponse 在<一个href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.workflowhostingendpoint.onresolvebookmark(v=vs.110).aspx"相对=nofollow> OnResolveBookmark

 保护覆盖书签OnResolveBookmark(对象[]输入的OperationContext的OperationContext,WorkflowHostingResponseContext responseContext,出对象的值)
{
    收藏书签= NULL;
    值= NULL;
    如果(operationContext.IncomingMessageHeaders.Action.EndsWith(ResumeBookmark))
    {
        通过客户端提供的输入IWorkflowCreation.ResumeBookmark //书签名称
        书签=新书签((串)输入[1]);
        通过客户端提供的参数IWorkflowCreation.ResumeBookmark //值
        值=(字符串)输入[2];

        //!在这里呼吁,例如。 !
        responseContext.SendResponse(NULL,NULL);
    }
    其他
    {
        抛出新的NotImplementedException(operationContext.IncomingMessageHeaders.Action);
    }

    返回书签;
}
 

这是简单地指出这里

  

覆盖OnResolveBookmark手动提取从书签   收到的消息。如果覆盖此方法,你必须调用   SendResponse在其主体上,以便于发送到所述响应消息   WorkflowHostingEndpoint

我不知道这是否可以被看作是或不是一个错误。工作流引擎似乎进入一个状态,虽然它变为空闲状态,因为你给它一个书签,它并没有真正的知它的,因为响应警告它永远不会发送。

I've an application that host WF4.5 workflow in IIS using WorkflowServiceHost, WorkflowServiceHostFactory and WorkflowHostingEndpoint.

The workflow is defined by VS 2013 in a .xaml file. In the workflow a have a custom activity for receive input data from a user. Get that using CreateBookmark and the callback for 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.

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.

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.

WorkflowServiceHost doesn't give you much control over when workflow instance is persisted but you can configure the when. Check How to: Configure Idle Behavior with 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. 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. 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. 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

<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. 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

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. If you override this method, you must invoke SendResponse in its body so as to respond to the message sent to the 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.

这篇关于WF 4.5书签自定义活动不火持续/卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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