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!



[f1]
[f2]

One thought on “Activity correlation using a RequestReplyCorrelationInitializer

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>