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.
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);
}
Now if I select my ReceiveActivity from workflow designer, can see some of its properties in properties window.
This activity has a ServiceOperationInfo property. You can choose this property and open Choose Operation dialog to select your service contract and 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.
Now I add a code activity to my workflow to implement my logic for this service operation.
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.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
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;
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),
public String receiveActivity1_message1
return ((string)(base.GetValue(ReceiveActivitySample.Workflow1.receiveActivity1_message1Property)));
base.SetValue(ReceiveActivitySample.Workflow1.receiveActivity1_message1Property, value);
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.
Original Post: ReceiveActivity in Windows Workflow Foundation 3.5
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.