Custom Compensation Sample

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample shows how to use CompensableActivity and its compensation handler to define custom compensation logic. The scenario modeled in this sample is a Truck Rental Agency.

Sample Details

The steps simulated are:

  1. The user requests truck rental quotes for a given date.

  2. Three truck companies are contacted and the three quotes are provided.

  3. The user selects one truck quote and proceeds to order by credit card.

  4. The application cancels the other two truck quotes.

  5. The application charges a service fee that is non-refundable for non-premium accounts if cancelation happens 10 days or less prior to the reservation date.

  6. The application charges the truck rental fee.

  7. The application waits until the reservation date or until the customer decided to cancel the reservation, whichever comes first.

  8. If the customer cancels the reservation, the CompensationHandler custom compensation logic runs according to the following logic:

    1. If the customer has a non-premium account and it is less than 10 days prior to the reservation date, then the service fee is still charged; otherwise, the application refunds the service fee.

    2. The rest of the compensable activities (truck order + truck order fee) are run according to the default compensation logic, which is to compensate in reverse order of execution.

To set up, build, and run the sample

  1. Using Visual Studio 2010, open the CustomCompensation.sln solution. It is located in the \WF\Basic\Compensation\CustomCompensation directory.

  2. Press CTRL+SHIFT+B to build the solution.

  3. Press CTRL + F5 to run the application.

Dd483319.Important(en-us,VS.100).gif Note:
The samples may already be installed on your machine. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\Compensation\CustomCompensation