一个简单的自定义工作流活动
这个简单的Custom Workflow Activity演示如何创建自定义活动,并在其中调用第三方的dll。
首先假设我们拿到了一个第三方提供的接口,该接口是用dll的形式提供的,我们要实现一个自定义工作流活动并且调用dll中的方法。
code:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
// Microsoft Dynamics CRM namespaces
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;
using Microsoft.Crm.Workflow.Activities;
using Microsoft.Crm.Sdk.Query;
//Third Party namespaces
using ThirdPartyFactory;
namespace CustomWorkflowActivity
{
[CrmWorkflowActivity("Test", "Custom Workflow Activity")]
public class TestActivity : SequenceActivity
{
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
try
{
// Get access to the Microsoft Dynamics CRM Web service proxy.
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();
// TODO: Workflow activity business logic goes here.
# 初始化并调用
ThirdPartyClass message = new ThirdPartyClass((String)InputParameter1);
int result = message.Test();
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
String.Format("An error occurred in the {0} plug-in.",
this.GetType().ToString()),
ex);
}
return ActivityExecutionStatus.Closed;
}
/// <summary>
/// 输入参数
/// </summary>
public static DependencyProperty InputParameter1Property =
DependencyProperty.Register("InputParameter1", typeof(System.String), typeof(TestActivity));
[CrmInput("InputParameter1")]
public String InputParameter1
{
get
{
return (String)base.GetValue(InputParameter1Property);
}
set
{
base.SetValue(InputParameter1Property, value);
}
}
}
}
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
// Microsoft Dynamics CRM namespaces
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;
using Microsoft.Crm.Workflow.Activities;
using Microsoft.Crm.Sdk.Query;
//Third Party namespaces
using ThirdPartyFactory;
namespace CustomWorkflowActivity
{
[CrmWorkflowActivity("Test", "Custom Workflow Activity")]
public class TestActivity : SequenceActivity
{
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
try
{
// Get access to the Microsoft Dynamics CRM Web service proxy.
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();
// TODO: Workflow activity business logic goes here.
# 初始化并调用
ThirdPartyClass message = new ThirdPartyClass((String)InputParameter1);
int result = message.Test();
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
String.Format("An error occurred in the {0} plug-in.",
this.GetType().ToString()),
ex);
}
return ActivityExecutionStatus.Closed;
}
/// <summary>
/// 输入参数
/// </summary>
public static DependencyProperty InputParameter1Property =
DependencyProperty.Register("InputParameter1", typeof(System.String), typeof(TestActivity));
[CrmInput("InputParameter1")]
public String InputParameter1
{
get
{
return (String)base.GetValue(InputParameter1Property);
}
set
{
base.SetValue(InputParameter1Property, value);
}
}
}
}
注:第三方的dll要拷贝到 服务器 “C:\Program Files\Microsoft Dynamics CRM\Server\bin”目录。
浙公网安备 33010602011771号