I was goofing around with Compensation blocks, as I prepare for the BizTalk 2010 Certification exam. I expect to get one or two questions about Compensations, so I at least wanted to play around with them some. I use scopes for exception handling all the time. However, compensation isn’t something I have really implemented.
That being said, I was having a little bit of trouble actually getting a Compensation block to fire. Well, it was for one simple reason – like “smack your forehead simple.” Fortunately, the wonderful interwebs contained the answer.
- The Compensation section for a scope gets
activatedonly when the scope terminates normally or the scope completes its execution.
I was trying to stack a compensation block underneath an exception block. That use case violates this rule. In order to compensate, I had to create nested scopes, such that the inner scope transaction completed, and the exception occurs afterward (I purposely caused a div by zero error). Then the outer scope’s exception handler calls the compensation block of the inner transaction scope.
This article (from way back in 2006!) has great screen shots and useful information about compensation in BizTalk.