WF GetRuntimeValue 错误的解决方法123
2009-10-16 12:23 Fred-Xu 阅读(246) 评论(0) 编辑 收藏 举报
在WCF+WF开发当中,使用自定义活动定义活动属性(DependencyProperty),如下代码: ///<Summary>
/// result
///</Summary>
public static DependencyProperty resultProperty = DependencyProperty.Register("result", typeof(string), typeof(ProjectAuditActivity));
[Description("审核结果")]
[Category("Data")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string result
{
get { return (string)this.GetValue(ProjectAuditActivity.resultProperty); }
set { this.SetValue(ProjectAuditActivity.resultProperty, value); }
}
自定义了一个属性,然后在工作流设计里加入这个自定义活动,并对其进行配置,如图:
///</Summary>
public static DependencyProperty resultProperty = DependencyProperty.Register("result", typeof(string), typeof(ProjectAuditActivity));
[Description("审核结果")]
[Category("Data")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string result
{
get { return (string)this.GetValue(ProjectAuditActivity.resultProperty); }
set { this.SetValue(ProjectAuditActivity.resultProperty, value); }
}
把定义的属性绑定好数据,配置好,调试一下工作流。
假如我们执行一个事件,代码如下:
public void ProjCheckApprove(TmTpCheck model)
{
WorkflowInstance instance = wfRuntime.GetWorkflow(model.guid);
//WorkflowInstance instance = GetWorkflowByID(model.guid);
ProjWorkflowService wfService = wfRuntime.GetService<ProjWorkflowService>();
wfService.RaiseProjectApprove(model);
}
{
WorkflowInstance instance = wfRuntime.GetWorkflow(model.guid);
//WorkflowInstance instance = GetWorkflowByID(model.guid);
ProjWorkflowService wfService = wfRuntime.GetService<ProjWorkflowService>();
wfService.RaiseProjectApprove(model);
}
/// <summary>
/// 审核通过项目
/// </summary>
/// <param name="_tmTpCheck"></param>
public void RaiseProjectApprove(TmTpCheck _tmTpCheck)
{
if (OnProjectApprove != null)
{
tm_tp_checkEventArgs e = new tm_tp_checkEventArgs(_tmTpCheck.guid, _tmTpCheck);
e.WaitForIdle = true;
OnProjectApprove(null, e);
}
}
/// 审核通过项目
/// </summary>
/// <param name="_tmTpCheck"></param>
public void RaiseProjectApprove(TmTpCheck _tmTpCheck)
{
if (OnProjectApprove != null)
{
tm_tp_checkEventArgs e = new tm_tp_checkEventArgs(_tmTpCheck.guid, _tmTpCheck);
e.WaitForIdle = true;
OnProjectApprove(null, e);
}
}
运行后,就会报错,提示“GetRuntimeValue 出错/失败”,某个属性为Null。其实这个传进来的数据参数已经获取了,原因在于工作流中没有声明这个参数数据。
例如传进来的数据实体类型RaiseProjectApprove(TmTpCheck _tmTpCheck)是TmTpCheck,那么你也要在工作流的cs文件中定义一个该类型作为内部调用,如下代码:
public sealed partial class ProjMgrWorkflow : StateMachineWorkflowActivity
{
#region Public Data 公共数据实体
private TmTpProject internalProjectData;
public TmTpProject ProjectData
{
get { return internalProjectData; }
set { internalProjectData = value; }
}
{
#region Public Data 公共数据实体
private TmTpProject internalProjectData;
public TmTpProject ProjectData
{
get { return internalProjectData; }
set { internalProjectData = value; }
}
加了这段代码,这个GetRuntimeValue错误就解决啦。
ps.博主刚刚开始接触wwf,博文里难免会出现一些表达上和认识上的偏差,希望各位能够予以指出和批评。谢谢。