locked
Setting Send-ReceiveReply correlation from code RRS feed

  • Question

  • Ihave two activities: Send and ReceiveReply - i wan't to correlate them from the code without using CorrelationScope. I have tried setting up RequestReplyCorrelationInitializet for Send activity but it does not work. When trying to run Activity configured like that i get InvalidOperationException.

    If someone could supply example of setting Send-ReceiveReply correlation in  code without CorrelationScope it would be great :)

    Tuesday, July 12, 2011 1:43 PM

Answers

  • Hi, Stefan

    Here is a sample from my book:

    class ReceiveAndReplyWorkflow {
            public WorkflowService GetInstance() {
                WorkflowService service;
                Variable<int> x = new Variable<int> { Name = "x" };
                Variable<int> y = new Variable<int> { Name = "y" };
                Variable<int> addResult =
                    new Variable<int> { Name = "addResult" };
                Receive receive = new Receive {
                    ServiceContractName = "ICalculateService",
                    OperationName = "GetData",
                    CanCreateInstance = true,
                    Content = new ReceiveParametersContent {
                        Parameters ={
                            {"xIn",new OutArgument<int>(x)},
                            {"yIn",new OutArgument<int>(y)}
                        }
                    }
                };
                Sequence workflow = new Sequence() {
                    Variables = { x, y, addResult },
                    Activities = {
                        new WriteLine{Text="WF service is starting..."},
                        receive,
                        new WriteLine{Text="receive request with two numbers"},
                        new WriteLine{
                            Text=new InArgument<string>(aec =>
                                "x="+x.Get(aec).ToString()+" y="+y.Get(aec)
                            )
                        },
                        new Assign<int>{
                            Value=new InArgument<int>(aec=>x.Get(aec)+y.Get(aec)),
                            To=new OutArgument<int>(addResult)
                        },
                        new WriteLine{
                            Text=new InArgument<string>(aec=>
                                "addResult="+addResult.Get(aec).ToString()
                            )
                        },
                        new WriteLine{Text="Then send the result back to client"},
                        new SendReply{
                            Request=receive,
                            Content=new SendParametersContent{
                                Parameters={
                                    {"addResult",new InArgument<int>(addResult)},
                                },
                            },
                        },
                        new WriteLine{Text="sent result back done"}
                    },
                };
                service = new WorkflowService {
                    Name = "AddService",
                    Body = workflow
                };
                return service;
            }
        }

    If you want to configure correlation in WF4 designer, see also this one:
    http://xhinker.com/post/WF4Correlate-Multiple-Receive-Activities.aspx

    Regards

     


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Thursday, July 21, 2011 6:51 AM
    Monday, July 18, 2011 2:49 AM