locked
Is the SendAndReceiveReply activity synchronous? RRS feed

  • General discussion

  • If I put a SendAndReceiveReply activity in a Parallel activity branch (let's say I have multiple branches with these activity types in them), isn't this activity synchronous, ie, it waits until the response before handing over control to the next branch?

    I've been using separate Send (to a one-way WCF call) and then Receive to make it asynchronous, but someone told me that the SendAndReceiveReply activity automatically knows how to do that.

    If that is correct, is it documented somewhere?


    STom

    Wednesday, May 9, 2012 1:44 PM

All replies

  • Hi,

    ->If I put a SendAndReceiveReply activity in a Parallel activity branch (let's say I have multiple branches with these activity types in them), isn't this activity synchronous, ie, it waits until the response before handing over control to the next branch?

    The Send activity is asynchronous activity, if you put SendAndReceiveReply activities in a Parallel activity's branches, they will execute concurrently. For the detailed information, you can refer to:

    The Workflow Parallel Activity and Task Parallelism

    http://blogs.msdn.com/b/rjacobs/archive/2011/06/28/the-workflow-parallel-activity-and-task-parallelism.aspx


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 10, 2012 6:07 AM
  • That article states that the 'Send' activity, which is an activity by itself would execute concurrently, it does not mention the SendAndReceiveReply.  Are you saying that because the Send is a part of the SendAndReceiveReply activity, it therefore is asynchronous?

    What's interesting is that I can't find any info on MSDN about the SendAndReceiveReply activity.

    Thanks!


    STom

    Friday, May 11, 2012 12:46 AM
  • Hi,

    Yes, the Send activity is a part of the SendAndReceiveReply "activity". When place SendAndReceiveReply into a parallel branches, the branches will execute concurrently. SendAndReceiveReply is a factory which is used to create a configured instance of SendReply and Receive activity pairs.

    http://msdn.microsoft.com/en-us/library/ee404233

    Actually, we can create our own activity factory by implementing IActivityTemplateFactory interface.

    http://msdn.microsoft.com/en-us/library/ee425918

    Hope this helps, thanks.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by LeoTang Friday, May 11, 2012 9:24 AM
    Friday, May 11, 2012 9:17 AM
  • >What's interesting is that I can't find any info on MSDN about the SendAndReceiveReply activity.

    To clarify Leo's answer, SendAndReceiveReply that you see in the toolbox isn't a real type. It's actually just creating a Sequence with a Send activity and ReceiveReply activity preconfigured inside.
    Tim
    Saturday, May 12, 2012 6:38 AM
  • Thanks Tim!

    What I don't understand here is how an activity, even a single Send activity, can call a WCF request/response operation and yet still be asynchronous when it comes to it's use in a parallel activity. Of course, this would be a nice feature for it to immediately go to the next branch while waiting on a response in the currently operating branch.

    However, I could also see the case where I actually 'do' want it to wait for the WCF call to come back before it went to the next branch. In that case, sure I could take the SendAndReceive activity out of the parallel activity and just place it in the workflow sequentially.

    Thanks again!


    STom

    Saturday, May 12, 2012 11:17 AM
  • I think terminology led to confusion here.

    When you say asynchronous 'in a parallel activity', you're probably talking about whether execution switches to another branch of the parallel activity.

    In the case of just a send activity, this is basically a question of how is Send activity is implemented, but it may also depend on whether the specific networking stack managed to complete the operation synchronously or asynchronously at runtime (based on OS scheduling behavior). Bottom line is you really shouldn't care - because if you put stuff in a parallel activity next to other stuff, it is meant to be a declaration that you don't care at all what order they execute in.

    This is maybe different to the question of whether the messaging operation (send/receive) is asynchronous or synchronous 'messaging operation'. A send with receivereply can arguably be said to be doing a 'synchronous' messaging operation in that the client making the call is waiting for the operation to come back before doing something else - especially if it does no other activity in parallel.

    In traditional single-threaded client apps, the very act of waiting for response at all instantly makes your call 'synchronous'. In WF it's not so clear-cut since other work can be happening in parallel to the call. From that point of view, it's not really synchronous.

    In any case, you appear to have arrived at the answer! Use a sequence activity if you want sequencing. :)

    >however, I could also see the case where I actually 'do' want it to wait for the WCF call to come back before it went to the next branch. In that case, sure I could take the SendAndReceive activity out of the parallel activity and just place it in the workflow sequentially.

    Tim

    Sunday, May 13, 2012 7:06 AM
  • Hi Tim,

    I appreciate your response but I don't think I have arrived at an answer.

    What I need to know is, if I use a SendAndReceiveReply activity in a parallel activity and this activity is calling a WCF request/response operation, will each activity have to wait until it gets a response before moving to the next branch?

    Of course the WF is single threaded and I shouldn't care what order the branches execute in, but this is not the topic. The topic is that I need to know if the branches will execute simultaneously, not synchronously.

    Thanks!


    STom

    Sunday, May 13, 2012 11:02 AM
  • What I need to know is, if I use a SendAndReceiveReply activity in a parallel activity and this activity is calling a WCF request/response operation, will each activity have to wait until it gets a response before moving to the next branch?

    In theory yes, and also I think you'll see it happens in practice if you try. But it's good not to rely on any particular execution order.

    For instance, it's implementation dependent on Send and ReceiveReply activities. Which could change some day! And it can vary basd on each time you run the activity depending on whether the underlying channel stack APIs completely synchronously (because e.g. there's already a message there sitting in the queue to read) or asynchronously.

    Is your main concern behind the original question related to the subject of how to get a high throughput of messages, or something else, like what to expect on the callee side?
    Tim

    Tuesday, May 15, 2012 2:35 AM
  • Hi Tim,

    I tested this for myself using a parallel activity with 3 SendAndReceive activities in it. The activities do operate asynchronously.

    I tested this by putting thread.sleep code in each service being called and it always finished in the order of shortest sleep to longest sleep no matter which service (or parallel branch) the activities were in.

    I still think though that this should be documented on msdn as to how this activity works.

    Thanks!


    STom

    Tuesday, May 15, 2012 10:06 AM