none
Transactions in services with request reply pattern

    Question

  • Can TransactionScopeActivity be placed inbetween Receive and Send of receiveAndSendActivity
    Wednesday, November 04, 2009 10:13 AM

Answers

  • When using two way messaging you should not place a transaction scope between the Receive and Send of a request/reply pair.  This is because the persistence point at the completion of the TransactionScope will fail since the workflow cannot be persisted before the response is sent.

    Instead, you should use a TransactedReceiveScope.  This will provide behavior similar to a TransactionScopeRequired operation in a code based WCF service.

    new TransactedReceiveScope
    {
        Request = new Receive { ... },
        Body = new Sequence
        {
            Activities =
            {
                new DoDatabaseWork(),
                new Send { ... } // Send the reply
            }
        }
    }
    Wednesday, November 04, 2009 8:36 PM
    Moderator

All replies

  • When using two way messaging you should not place a transaction scope between the Receive and Send of a request/reply pair.  This is because the persistence point at the completion of the TransactionScope will fail since the workflow cannot be persisted before the response is sent.

    Instead, you should use a TransactedReceiveScope.  This will provide behavior similar to a TransactionScopeRequired operation in a code based WCF service.

    new TransactedReceiveScope
    {
        Request = new Receive { ... },
        Body = new Sequence
        {
            Activities =
            {
                new DoDatabaseWork(),
                new Send { ... } // Send the reply
            }
        }
    }
    Wednesday, November 04, 2009 8:36 PM
    Moderator
  • I've been considering doing something similar to the above but am wondering how (or indeed if) it is possible to do this within a Pick ? Basically, following the guidance for implementing a State Machine using a FlowChart , I have Pick activities with Receive's as triggers and SendReply's in the action. So in each state it awaits any of the appropriate triggers and and reacts accordingly for that state. I had tried to wrap some db logic up within several actions but it fails with the above error. I was going to attempt to extend PickBranch to wrap all this together but found it was sealed.

     

    Any suggestions or simpler ways to achieve this would be much appreciated! Fresh eyes could be just what's needed!

    Thursday, April 01, 2010 2:49 AM
  • I've been considering doing something similar to the above but am wondering how (or indeed if) it is possible to do this within a Pick ? Basically, following the guidance for implementing a State Machine using a FlowChart , I have Pick activities with Receive's as triggers and SendReply's in the action. So in each state it awaits any of the appropriate triggers and and reacts accordingly for that state. I had tried to wrap some db logic up within several actions but it fails with the above error. I was going to attempt to extend PickBranch to wrap all this together but found it was sealed.

     

    Any suggestions or simpler ways to achieve this would be much appreciated! Fresh eyes could be just what's needed!
    Thursday, April 01, 2010 2:49 AM