
How This Sample is Designed and Why
A Scope shape is primarily used for transactional execution and exception handling, including compensation. A scope consists of two blocks. The first block is the context block and the second block can be one or more exception-handling or compensation blocks. This is similar to the try-catch statement in the .NET programming language. In the UpdateContact.odx orchestration, there are two parallel actions. At the right-side branch, the try block is the Scope shape named Updated Backend Systems, which has a Long-Running transaction type and an Upd_Backend transaction identifier. Further down in the flow, there is a catch block that catches the general exception and initiates the compensation.
For more information about the Scope shape, see Scopes. Also see How to Configure the Scope Shape.
Note |
|---|
|
The orchestration must itself be a long-running transaction for you to set the transaction type to Atomic or Long-Running.
|
In the try block, there are two scopes named Update CRM and Update Mailing. Both of these scopes are atomic transactions. In the Update CRM scope, there is a try block and a compensation block. The try block updates the Northwind database through a method call to an external assembly. The compensation block is where the compensation action takes place. When an exception happens in the Update Backend Systems scope, the code in Undo CRM Expression Shape updates the record back to its original state. This is triggered by the Compensate shape in the Catch Exception block.
Note |
|---|
|
Atomic transactions guarantee that any partial updates are rolled back automatically in the event of a failure during the transactional update, and that the effects of the transaction are erased (except for the effects of any .NET calls that are made in the transaction).
|
Note |
|---|
|
A long-running transaction is considered committed when the last statement in it has completed. There is no automatic rollback of state in case of a transaction abort. You can achieve this programmatically through the exception and compensation handlers demonstrated in this sample.
|
In the catch block, there is one Delay shape set for ten seconds. This delays the compensation action. There is also a Compensate shape that initiates the compensation action in the Upd_Backend transaction.
The following happens after the orchestration receives the input message:
-
The UpdateCrm assembly updates a row in the Northwind database.
-
The UpdateMailingList assembly updates a matching record in the BTSCompensationSampleMailingList database.
-
In the event of a failure while updating the Northwind database, an exception is raised and the orchestration exits the process.
-
In the event of a failure while updating the BTSCompensationSampleMailingList database, an exception is raised and a ten-second delay takes place before rewriting the original customer data back to the Northwind database.