There are several occasions where we use Atomic scopes in BizTalk. For instance, invoking a web service proxy as a class library or invoking a custom .NET component. In this article, we shall learn a way to retry/re-execute the code within the Atomic shape several times using a
If you are new to Atomic scopes and would like to learn more, have a look at my article Parallel Branching and Scoping in BizTalk Orchestrations - Advanced Concepts.
Retrying an Atomic Scope
An Atomic scope does NOT have an exception block, but BizTalk provides a compensation section. In order for an atomic scope to be retried, we shall need to do the following:
- Set the
Retry property for the scope to
- The component invoked must throw an instance of
- Create an sub-scope which shall catch the exception and throw an instance of
The example orchestration below uses the sub-scope approach to retry Atomic scopes.
The above figure depicts the scopes used, to correctly use the
RetryTransactionException exception functionality.
- The orchestration must have the 'Transaction Type' property set to 'Long Running Transaction (LRT)'.
- The Main scope uses a 'Transaction Type' set to 'Long Running Transaction (LRT)'.
- The Main scope contains the Atomic scope.
- The Atomic scope contains a scope (Transaction=NONE) which has an exception block.
The exception block contains the following code...
throw new Microsoft.XLANGs.BaseTypes.RetryTransactionException();
Orchestration Control Flow
The sub-scope contained within an Atomic scope throws an exception, this exception is caught by the exception block of the sub-scope. The expression shape in the exception section throws an instance of
- Use the
RetryTransactionException to retry Atomic scopes without having to write an extra line of code.
- Throwing the exception
RetryTransactionException shall retry the Atomic scope atleast 21 times.
- Use the property
DelayFor of the
RetryTransactionException to set the time interval for retry.
- 27th January, 2009: Initial post