您的位置:首页 > 其它

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

2009-07-23 12:16 706 查看
搭建自己的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,所以也会导致这样的错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐