在workflow中,无法为实例 ID“...”传递接口类型“...”上的事件“...” 问题的解决方法。

搭建自己的WF程序时碰到这样的错误:无法为实例 ID“b6badb4d-5955-4d2c-8e10-bf51fb0c6f56”传递接口类型“Land.Workflow.LocalService.ICaseService”上的事件“Create”。

搜了下,基本上都是这样的说法:把WaitForIdle 属性设置为true即可,如:args.WaitForIdle = true; 照做还是不行。

通过仔细研究发现,我们的一般会这样自定义自己的消息类型:
[Serializable]
public class CaseEventArgs : ExternalDataEventArgs
{
public CaseEventArgs(Guid instanceId)
: base(instanceId)
{
}

public CaseEventArgs(Guid instanceId, Case _case) :
base(instanceId)
{
this.Case = _case;
}

public Case Case
{
get;
set;
}
}

public class Case
{
}

CaseEventArgs 的[Serializable]是必须加的,这地球人都知道。
但是Case如果不加[Serializable]属性同样会出现无法传递事件错误。改成这样即可:
[Serializable]
public class Case
{
...
}

也就是CaseEventArgs中属性设涉及到的实体,必须都可序列化,因为其本身可序列化。

 

 

还有一种原因导致的
在微软的教材会教我们,创建WorkflowRuntime的时候,使用WorkflowFactory类(微软推荐的类),在里面写函数
public static WorkflowRuntime GetWorkflowRuntime()
{
lock (lockObject)
{
if (workflowRuntime == null)
{
// prev for shutdown
AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkflowRuntime);
workflowRuntime = new WorkflowRuntime();
}

string dataBaseConnetion = ConfigurationManager.ConnectionStrings["TrackingDatabase2"].ConnectionString;
SqlTrackingService sqlTrackingService = new SqlTrackingService(dataBaseConnetion);
workflowRuntime.AddService(sqlTrackingService);

workflowRuntime.StartRuntime();
return workflowRuntime;
}
}

在创建 workflowRuntime.StartRuntime();这句话,他们推荐在这个里面写,因为你创建workflowRuntime的时候必然要StartRuntime,很多人在使用这个的时候,忘记了,在workflowRuntime的AddService方法之前不能StartRuntime,所以也会导致这样的错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值