Transaction Help


  • Hi All,

    I have certain questions pertaining to custom composite activities.

    1) If a custom composite activity has a compenstableTransactionScope activity how to set the compensate activity to this custom activity in a workflow?

    2) In a workflow that uses this composite activity with compensatableTransactionScope, can there be another transaction scope nesting the composite activity and other activities?

    3) What is the best way to syncronize transactions in custom composite activities and in workflow?

    Any guidance is much appreciated.



    Tuesday, December 12, 2006 12:37 AM


  • Hi Stags,

    1. You can add compensate activity to the exception handler or compensation handler or faulthandler of the activity enclosing the CompensatableTransactionScope activity. In other words, if you want to use CompensateActivity, you can compensate only the immediate child activity which implements ICompensatableActivity interface.
    Compensation can be triggered in 3 ways.

    Explicit Compensation: This is done using the CompensateActivity as mentioned above

    Implicit or Default compensation: This can be done without using a Compensate activity. The compensation code of any nested successfully completed compensatable activities is run automatically if there is an unhandled exception in the workflow. This means you cannot handle the exception and your workflow terminate.

    Self Compensation: In CompensateActivity, set TargetActivityName to point to the activity which is containing the CompensateActivity. This will trigger compensation on all the nested activities.

    SDK docs have some good information about all this.


    2. You cannot nest activities which support transactions

    3. Everytime a transaction activity executes, we create a new transaction and it commits after the activity completes successfully. So you cannot really synchronize different transactions. One way will be use one TransactionScope activity and add all your custom activities which need to do transactional work to that activity.

    However, if you have a custom service and want it to participate in the same transaction as that of the workflow, you can participate in the work batch of the workflow. Take a look at the WorkflowCommitWorkBatch Service sample.

    Hope this helps

    Wednesday, December 13, 2006 1:14 AM