创建自定义通信活动

Windows Workflow Foundation 实现一组基类,这些类使服务类提供程序能够将通信作为自定义服务公开。 即,服务类方法和事件可以直接转换为一组扩展的特定于域的活动,它们可以隐藏消息和相关集的详细信息, 甚至可以使活动作者看不到这些详细信息。 可以直接根据接口定义来编写这些新活动,且活动作者可直接借助服务类的接口来实现这些活动。

将服务类作为活动公开

下一节介绍如何将服务类作为表示特定域中操作的一组扩展活动公开。

CallExternalMethodActivityHandleExternalEventActivity 活动可用于在工作流通信服务接口上发送和接收消息,这些接口由 ExternalDataExchangeAttribute 属性标识。

类接口上的每个方法和事件都可通过使用与该方法和事件匹配的自定义活动在编程模型中表示出来。

实现自定义通信活动

活动作者为每个方法构建一个新的活动,并且为服务类接口中的每个事件构建一个活动。 此示例使用在在工作流中使用本地服务中创建的通信接口。

    // Handle External Event Activity.
    [ToolboxItemAttribute(typeof(ActivityToolboxItem))]
    public partial class HelloWorkflow : HandleExternalEventActivity 
    {
        
        public HelloWorkflow() 
        {
            base.InterfaceType = typeof(ClassLibrary1.ICommunicationService);
            base.EventName = "HelloWorkflow";
        }
    }
    
    // Call External Method Activity.
    [ToolboxItemAttribute(typeof(ActivityToolboxItem))]
    public partial class HelloHost : CallExternalMethodActivity 
    {
        public static DependencyProperty messageProperty = DependencyProperty.Register("message", typeof(string), typeof(HelloHost));
        
        public HelloHost() 
        {
            base.InterfaceType = typeof(ClassLibrary1.ICommunicationService);
            base.MethodName = "HelloHost";
        }
        
        [ValidationOptionAttribute(ValidationOption.Required)]
        public string message 
        {
            get 
            {
                return ((string)(this.GetValue(HelloHost.messageProperty)));
            }
            set 
            {
                this.SetValue(HelloHost.messageProperty, value);
            }
        }
        
        protected override void OnMethodInvoking(System.EventArgs e) 
        {
            this.ParameterBindings["message"].Value = this.message;
        }
    }

请参见

概念

在工作流中使用关联
创建自定义活动
在工作流中使用本地服务
工作流和应用程序通信

其他资源

Communications Samples
Custom Activities Samples

Footer image

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。