External Activity Validation
This topic applies to Windows Workflow Foundation 4 (WF4).
This sample shows how to add validation logic to a built-in activity that you are not the author of. The validation logic consists of enforcing that all If activities present in the workflow either have their Then property set or their Else property set. Also, the validation logic includes checking that all Pick activities present in the workflow have more than one branch, and if that is not the case, a warning is generated.
Sample details
This sample creates a workflow with an instance of each activity to validate: the If activity and the Pick activity. A Constraint is created for each validation behavior. The constraints created in this sample are ConstraintError_IfShouldHaveThenOrElse
and ConstraintWarning_PickHasOneBranch
. Next, these constraints are added to the AdditionalConstraints
collection of a ValidationSettings instance. Finally, the static Validate method of ActivityValidationServices is called to validate the activities in the workflow and the validation results are printed out to the console.
Note
You can add policy constraints to any activity. For example, you can add a policy constraint to a Sequence or Parallel activity.
To use this sample
Using Visual Studio 2010, open the ExternalActivityValidation.sln file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press Ctrl+F5.
![]() |
---|
The samples may already be installed on your computer. 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\Validation\ExternalActivityValidation
|