I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
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.
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.
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.

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:

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));
}
}
}
Now I run my workflow to get the following result:
Keyvan Nayyeri
Aug 17, 2007 11:37 AM
#
sean
Mar 10, 2009 1:58 PM
#
you had me until the channel token. Could you elaborate a little more, by defaulkt I have wshttpbinding. Can you send a link for your solution?
sean
Mar 10, 2009 2:42 PM
#
Did not work!
Leave a Comment