Tracking an Expression activity in Windows Workflow Foundation

Since the nodes in a Flowchart do not derive from Activity, they do not have the tracking capabilities of activities. However, because Expressions are activities, it is possible to track the Condition property of a FlowDecision activity. The following code demonstrates how to create an Expression that can then participate in tracking.   public class…


Making an activity’s display name readonly in the Workflow 4 designer

To make an activity’s display name readonly, it isn’t enough to use the ReadOnlyAttribute on the DisplayName. In order to do this, create a custom PropertyValueEditor that displays a string in a text block, then declare an editor attribute on the “DisplayName” property of your activity. The following code demonstrates how to create a read-only…


Constraining what activities can be dropped on a custom activity designer in Workflow 4

When designing a custom activity that can be used as a container for other activities, you may want to restrict the activity user to a certain set of activities. If the custom activity can only accept a single type, this can be implemented quite simply by setting the WorkflowItemPresenter.AllowedItemType or WorkflowItemsPresenter.AllowedItemType property. Here is an…


Programmatically calling validation in a rehosted Workflow 4 designer

The workflow designer has a rich programming model that supports communication with the host. A rehosted workflow designer will automatically validate a workflow when it is changed; in order to programmatically call validation on demand on a rehosted designer, use the following method: designer.Context.Services.GetService<ValidationSErvice>().ValidateWorkflow(); To handle resulting validation errors, publish an implementation of IValidationErrorService, which…


WF 4 hosting options: IIS, AppFabric, and Windows Service

Most of the Windows Workflow Foundation samples use workflows that are hosted in a console application, but this isn’t a realistic scenario for real-world workflows. Workflows in actual business applications will be hosted in persistent processes- either a Windows service authored by the developer, or a server application such as IIS or AppFabric. The differences…


HttpContext.Current returning null when using NetTcpBinding in WCF4

When using NetTcpBinding, not all of the features of WCF are available, particularly those using HTTP. NetTcpBinding removes a dependency on HTTP (and IIS as a result, allowing the service to be hosted in WAS instead.) HttpContext.Current is one of the features in WCF that is not available when using NetTcpBinding.


Error message in WF4: "Error: The values provided for the root activity’s arguments did not satisfy the root activity’s requirements"

When loading an activity assembly using Assembly.LoadFrom, you may see the following error: “Error: The values provided for the root activity’s arguments did not satisfy the root activity’s requirements:                 ‘UserDefinedInputClass’: Expected an input parameter value of type ‘MyAssembly.UserDefinedClass’            for parameter named ‘UDC’. Parameter name: rootArgumentValues” Assembly.LoadFrom does not use the main application context;…


Workflow Designer: What properties appear in the Properties pane when activities are multi-selected?

When multiple activities are selected in the Workflow Designer surface with ctrl+click, it’s not immediately obvious which properties appear in the Properties pane, and can be set on multiple activities at a time. When activites are multi-selected, the following properties appear in the Properties pane: Properties that have a common name across all the selected…


Validation error message: "An error occurred while attempting to extract the target object of type ‘System.Activites.InArgument’ from the method call expression <activity><property>.Get"

When using the (non-Generic) version of InArgument, you may see the following error message during validation: The private implementation of activity ‘<activity>’ has the following validation error: “An error occurred while attempting to extract the target object of type ‘System.Activites.InArgument’ from the method call expression <activity><property>.Get”. Note that the expression determining the object of type…


Cancelling an AsyncCodeActivity

Even when AsyncCodeActivity.Cancel is called, the activity will still execute the EndExecute method, so it isn’t immediately obvious why a second path of execution is necessary. Implementing this method is useful only when AsyncCodeActivityContext.MarkCanceled is implemented, which in turn is useful mainly when cancellation is meaningful for the underlying operation (i.e. if work already completed…