The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Activity correlation using a RequestReplyCorrelationInitializer

Note: This blog post is written using the .NET framework 4.0 Beta 2

 

In my previous post about Windows Workflow Foundation 4 I used the CorrelationScope activity to arrange for the activity correlation between a Send and the related ReceiveReply activities. That is quite easy to do and personally I find things nice and easy to arrange with both messaging activities nested in the CorrelationScope activity . The default templates use a slightly different approach though and use a RequestReplyCorrelationInitializer. The end result is the same though so just use what you think best.

 

Just for comparison below is the code to create the same workflow with a RequestReplyCorrelationInitializer.

static Activity CreateWorkflow()
{
    var getDataResult = new Variable<string>();
    var handel = new Variable<CorrelationHandle>();
 
    var send = new Send()
    {
        CorrelationInitializers =
        {
            new RequestReplyCorrelationInitializer()
            { 
                CorrelationHandle = handel
            }
        },
        OperationName = "GetData",
        ServiceContractName = "IService1",
        Endpoint = new Endpoint()
        {
            Binding = new BasicHttpBinding(),
            AddressUri = new Uri("http://localhost:8080/GetDataService/")
        },
        Content = new SendParametersContent()
        {
            Parameters = 
            {
                {"value", new InArgument<int>(42)}
            }
        }
    };
 
    var receive = new ReceiveReply()
    {
        Request = send,
        Content = new ReceiveParametersContent
        {
            Parameters =
            {
                {"GetDataResult", new OutArgument<string>(getDataResult)}
            }
        }
    };
 
    var workflow = new Sequence()
    {
        Variables = { getDataResult, handel },
        Activities = 
        {
            send, 
            receive,
            new WriteLine() { Text = getDataResult } 
        }
    };
 
    return workflow;
}

 

The workflow is even a little simpler because there are fewer activities involved. And this is effectively the same as the SendAndReceiveReply and ReceiveAndSendReply templates generate in WF4.

 

Enjoy!

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Published Thu, Dec 3 2009 19:16 by Maurice
Filed under: , , , ,

Comments

# re: Activity correlation using a RequestReplyCorrelationInitializer@ Monday, January 25, 2010 2:07 AM

Hi, thanks for very useful WF4 posts!

I can't, however, figure out the Send activity. The ServiceContractName property in particular.  Shouldn't this be a reference to the contract type, not a string?  And no matter what I put in there it fails runtime.

Also, according to some posts, the Send activity requires the parameters to be wrapped in a magic way for the Send to work?

I hope to create the contracts runtime, using CodeDom, and can't rely on Visual Studio to help.

by Jørgen Tvedt