CSharpFeeds - All your C# feeds in one place.

Sponsors

Friday, August 17, 2007

ReceiveActivity in Windows Workflow Foundation 3.5

by Keyvan Nayyeri via Keyvan Nayyeri on 8/17/2007 6:37:14 PM

Last week, I talked about SendActivity in Windows Workflow 3.5 and today talk about ReceiveActivity.

This activity can be used in WCF services in order to listen for a specific service method and handle its logic in a workflow.  ReceiveActivity can work as a container for other activities and hold them as part of method logic.  It gets method parameters via properties or fields and sets the result of the method in a field or property.  When service method is called by the client, it returns this field or property as the result to the client.

Create a Service

To see this in action, I create a Sequential Workflow Service Library project (in Visual Studio 2008).  This generates a service contract file along a workflow for me.  The workflow file contains a ReceiveActivity by default.

Here is my simple service contract for this service:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

 

namespace ReceiveActivitySample

{

    [ServiceContract]

    public interface IWorkflow

    {

        [OperationContract]

        string GetText(string message);

    }

}

ReceiveActivity Properties

Now if I select my ReceiveActivity from workflow designer, can see some of its properties in properties window.

ReceiveActivity Properties

This activity has a ServiceOperationInfo property.  You can choose this property and open Choose Operation dialog to select your service contract and operation.

Choose Operation

This generates necessary properties for input and output parameters in properties window.  You can use these properties in order to bind their values to existing fields or properties in your workflow class or create new fields and properties for them.  I set my input and output parameters to appropriate dependency properties in my workflow class.

Implement the Logic

Now I add a code activity to my workflow to implement my logic for this service operation.

Workflow

In the execution code for the CodeActivity, I just add below code to return a text value to client.

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

    this.receiveActivity1__ReturnValue_1 =

        string.Format("Hello {0}", this.receiveActivity1_message1);

}

Therefore the final code for my workflow class looks like this:

using System;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

using System.Linq;

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;

 

namespace ReceiveActivitySample

{

    public sealed partial class Workflow1 : SequentialWorkflowActivity

    {

        public Workflow1()

        {

            InitializeComponent();

        }

 

        public String returnValue = default(System.String);

        public String inputMessage = default(System.String);

 

 

        public static DependencyProperty receiveActivity1__ReturnValue_1Property =

            DependencyProperty.Register("receiveActivity1__ReturnValue_1", typeof(System.String),

            typeof(ReceiveActivitySample.Workflow1));

 

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

        [BrowsableAttribute(true)]

        [CategoryAttribute("Parameters")]

        public String receiveActivity1__ReturnValue_1

        {

            get

            {

                return ((string)(base.GetValue(ReceiveActivitySample.Workflow1.receiveActivity1__ReturnValue_1Property)));

            }

            set

            {

                base.SetValue(ReceiveActivitySample.Workflow1.receiveActivity1__ReturnValue_1Property, value);

            }

        }

 

        public static DependencyProperty receiveActivity1_message1Property =

            DependencyProperty.Register("receiveActivity1_message1", typeof(System.String),

            typeof(ReceiveActivitySample.Workflow1));

 

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

        [BrowsableAttribute(true)]

        [CategoryAttribute("Parameters")]

        public String receiveActivity1_message1

        {

            get

            {

                return ((string)(base.GetValue(ReceiveActivitySample.Workflow1.receiveActivity1_message1Property)));

            }

            set

            {

                base.SetValue(ReceiveActivitySample.Workflow1.receiveActivity1_message1Property, value);

            }

        }

 

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

            this.receiveActivity1__ReturnValue_1 =

                string.Format("Hello {0}", this.receiveActivity1_message1);

        }

    }

 

}

At this point I can build my service and configure it to work as a self-hosted service or host it on IIS to get access to it like other WCF services.

You can download the source code sample for this post from here.

email it!bookmark it!digg it!

Original Post: ReceiveActivity in Windows Workflow Foundation 3.5

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us