CSharpFeeds - All your C# feeds in one place.

Sponsors

Tuesday, August 07, 2007

SendActivity in Windows Workflow Foundation 3.5

by Keyvan Nayyeri via Keyvan Nayyeri on 8/7/2007 5:54:17 PM

Windows Workflow Foundation in .NET Framework 3.5 comes with two new activities: SendActivity and ReceiveActivity.  These are two new services to work with WCF services.  The first one, SendActivity, can be used to send requests to WCF services and the second one, ReceiveActivity, can be used to receive the response from services.

In this post I talk about the SendActivity and in one of upcoming posts, I'll cover ReceiveActivity.

Create a Service

First, let me create a WCF service for this example which has a contract like this:

using System;

using System.Collections.Generic;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

 

namespace MyService

{

    [ServiceContract]

    public interface IMyService

    {

        [OperationContract]

        string GetResponse(string value);

    }

}

And a service implementation like this:

using System;

using System.Collections.Generic;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

 

namespace MyService

{

    public class MyService : IMyService

    {

        #region IMyService Members

 

        public string GetResponse(string value)

        {

            return string.Format("Hello {0}!", value);

        }

 

        #endregion

    }

}

I host this service on IIS 7.0.

Create a Workflow

On workflow side, you need to add references to your service assembly to have access to its types.  Moreover, you have to use Add Service Reference to add reference to your WCF service (this is a new replacement for Add Web Reference in Visual Studio 2008).

Now, I add two activities to my workflow: a SendActivity and a Code activity.  SendActivity sends a request to service and calls the GetResponse() method to get the result and store it in a DependencyProperty in workflow.  Code activity simply writes this property to console.

Workflow

After adding the SendActivity activity to workflow, you should set some properties in order to make it set it up.  Here is a list of important properties to set:

  • ReturnValue: A binding property that can be used to bind the result of service method to an existing property or field in workflow or add new property or field to bind to result.
  • AfterResponse: An event to add and implement any code that should be executed after getting the response from service.
  • BeforeResponse: An event to add and implement any code that should be executed before getting the response from service.
  • ChannelToken: This contains the endpoint information for the service.  You have to add the name of an endpoint to use for connecting to service as well as an owner activity for the activity. 
  • ServiceOperationInfo: This property is where you choose the service method that you want to call.  Using the Choose Operation dialog, you can import the service operation.
  • value: The list of parameter values that should be passed to service operation.

Properties Window

Now I add a simple code to show the response from DependencyProperty in console so the final code for the workflow looks like this:

using System;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

using System.Drawing;

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 SendActivitySample

{

    public sealed partial class Workflow1 : SequentialWorkflowActivity

    {

        public Workflow1()

        {

            InitializeComponent();

        }

 

        public static DependencyProperty sendActivity1__ReturnValueProperty = DependencyProperty.Register("sendActivity1__ReturnValue", typeof(System.String), typeof(SendActivitySample.Workflow1));

 

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

        [BrowsableAttribute(true)]

        [CategoryAttribute("Parameters")]

        public String sendActivity1__ReturnValue

        {

            get

            {

                return ((string)(base.GetValue(SendActivitySample.Workflow1.sendActivity1__ReturnValueProperty)));

            }

            set

            {

                base.SetValue(SendActivitySample.Workflow1.sendActivity1__ReturnValueProperty, value);

            }

        }

 

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

            Console.WriteLine(GetValue(Workflow1.sendActivity1__ReturnValueProperty));

        }

    }

}

Result

Now I run my workflow to get the following result:

Output

email it!bookmark it!digg it!

Original Post: SendActivity 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