Performing compensation by using Compensable activity

Imagine a scenario where we are buying a computer online and money has been deducted from our bank account. Suddenly an unexpected exception occurs, workflow stops, and the purchase gets cancelled. Obviously, such a thing should not happen in real life. If an exception occurs that induces workflow stop, the money should be returned back to our account. In WF4 we can use a Compensable activity to handle such a compensation job.

How to do it...

  1. Create a Workflow Console Application project:

    Create a new Workflow Console application project and name it UseCompensableActivity.

  2. Create workflow code:

    Add a new class file to the project and name it CompensationWokflow.cs. Fill the file with the following ...

Get Microsoft Windows Workflow Foundation 4.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.