Designer > Compensation > Compensation Handlers and Compensate Activities
  

Compensation Handlers and Compensate Activities

Compensation Handlers and Compensate Activities
You can add compensation handling as follows:
XML Syntax
<compensationHandler>
activity
</compensationHandler>
The following illustration compares default and specified compensation.
Default-order compensation
Default order compensation example
Specified compensation
Specified compensation example
Implicit Compensation
In the case where a scope does not define a compensation handler, the execution engine provides an implicit compensation handler. This handler contains a single <compensate> activity at compensates all of the enclosed scopes that have completed and are eligible for compensation. In general, you should only provide a compensation handler when you have some application-specific logic to execute in order to undo some previously executed logic.

Default-Order Compensation Example

Default compensation processing is available from the compensate activity with the form <compensate/>. The activity invokes the compensation handlers on all of the enclosed scopes that are eligible for compensation. The scope's compensation handlers are invoked in the reverse order of completion. If a scope executed multiple times in a <while> loop, it is eligible for each execution instance where it completed without having a fault generated.
The following example shows how a confirmed purchase order is canceled. The CancelPurchaseoperation compensates the SyncPurchase operation in an already completed Invoke activity.
<scope>
<compensationHandler>
<invoke partnerLink="Seller" portType="SP:Purchasing"
operation="CancelPurchase"
inputVariable="getResponse"
outputVariable="getConfirmation">
<correlations>
<correlation set="PurchaseOrder" pattern="request"/>
</correlations>
</invoke>
</compensationHandler>
<invoke partnerLink="Seller" portType="Sell:Purchasing"
operation="SyncPurchase"
inputVariable="sendPO"
outputVariable="getResponse">
<correlations>
<correlation set="PurchaseOrder" initiate="yes"
pattern="request"/>
</correlations>
</invoke>
</scope>

Specified Compensation Example

The following example shows how a Compensate activity is incorporated into a fault handler. For more information, see Fault Handling.
The following example shows how a Compensate activity is incorporated into a fault handler.
<faultHandlers>
<catch faultName="lns:loanProcessFault"
faultVariable="error">
<sequence name="fault-sequence">
<compensate scope="assessor-scope"/>
...
</sequence>
</catch>
</faultHandlers>