Condividi tramite


Creating Custom Communication Activities

Windows Workflow Foundation implements a set of base classes that enable a service class provider to expose communications as custom services. That is, the service class methods and events can be directly translated into an expanded set of domain-specific activities that hide all the details of messaging and correlation sets. These details can even be hidden from the activity author. The writing of these new activities is immediate from the interface definitions, and the activity author can implement in terms of the service class’s interfaces directly.

Exposing a Service Class as an Activity

The following section describes the presentation of a service class as an expanded palette of activities that represent actions in a specific domain.

The CallExternalMethodActivity and HandleExternalEventActivity activities can be used to send and receive messages on workflow communication services interfaces, which are identified by the ExternalDataExchangeAttribute attribute.

Each method and event on the class’s interface is represented in the programming model by using a custom activity that is matched to that method or event.

Implementing a Custom Communication Activity

The activity author builds one new activity for each method and one activity for each event in the service class’s interface. The communication interface that is used in this example is from Using Local Services in Workflows.

    // 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;
        }
    }

See Also

Concepts

Using Correlation in Workflows
Creating Custom Activities
Using Local Services in Workflows
Windows Workflow Foundation and Application Communication

Other Resources

Communications Samples
Custom Activities Samples