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...
Create a Workflow Console Application project:
Create a new Workflow Console application project and name it
UseCompensableActivity
.Create workflow code:
Add a new class file to the project and name it
CompensationWokflow.cs
. Fill the file with the following code:using System; using System.Activities; using System.Activities.Statements; namespace UseCompensableActivity { class CompensationWorkflow { public Activity GetInstance() { Variable<int> num1 = new Variable...