What's New in Windows Workflow Foundation in .NET 4.5
Windows Workflow Foundation (WF) in .NET Framework 4.5 Developer Preview has many new features, such as new activities, designer capabilities, and workflow development models.
Workflow versioning
.NET Framework 4.5 Developer Preview introduces several new versioning features based around the new WorkflowIdentity class. WorkflowIdentity provides workflow application authors a mechanism for mapping a persisted workflow instance with its definition.
-
Developers using WorkflowApplication hosting can use WorkflowIdentity to enable hosting multiple versions of a workflow side-by-side. Persisted workflow instances can be loaded using the new WorkflowApplicationInstance class, and then the DefinitionIdentity can be used by the host to provide the correct version of the workflow definition when instantiating the WorkflowApplication. For more information, see Using WorkflowApplication Identity and Versioning.
-
WorkflowServiceHost is now a multi-version host. When a new version of a workflow service is deployed, new instances are created using the new service, but existing instances complete using the previous version. For more information, see Side by Side Versioning in WorkflowServiceHost.
-
Dynamic update is introduced which provides a mechanism for updating the definition of a persisted workflow instance. For more information, see Dynamic Update.
Activities
The built-in activity library contains new activities and new features for existing activities.
NoPersist Scope
NoPersistScope is a new container activity that prevents a workflow from being persisted when the NoPersistScope’s child activities are executing. This is useful in scenarios where it is not appropriate for the workflow to be persisted, such as when the workflow is using machine-specific resources such as file handles, or during database transactions. Previously, to prevent persistence from occurring during an activity's execution, a custom NativeActivity that used a NoPersistHandle was required.
New Flowchart Capabilities
Flowcharts in .NET Framework 4.5 Developer Preview have the following new capabilities:
-
The DisplayName property of a FlowSwitch or FlowDecision activity is editable. This will let the activity designer show more information about the activity's purpose.
-
Flowcharts have a new property called ValidateUnconnectedNodes; the default for this property is False. If this property is set to True, then unconnected flowchart nodes will produce validation errors.
New Designer Capabilities
Designer Search
To make larger workflows more manageable, workflows can now be searched by keyword. This feature is only available in Visual Studio; this feature is not available in a rehosted designer. There are two kinds of searches available:
-
Quick Find, initiated with either Ctrl+F or Edit, Find and Replace, Quick Find.
-
Find in Files, initiated with either Ctrl+Shift+F or Edit, Find and Replace, Find in Files.
Note that Replace is not supported.
Quick Find
Keywords searched in workflows will match the following designer items:
-
Properties of Activity objects, FlowNode objects, State objects, Transition objects, and other custom flow-control items.
-
Variables
-
Arguments
-
Expressions
Quick Find is performed on the designer's Modelitem tree. Quick Find will not locate namespaces imported in the workflow definition.
Find in Files
Keywords searched in workflows will match the actual content of the workflow files. The search results will be shown in Visual Studio Find Results view pane. Double-clicking the result item will navigate to the activity which contains the match in workflow designer.
Delete context menu item in variable and argument designer
Previously, variables and arguments could only be deleted in the designer using the keyboard. In .NET Framework 4.5 Developer Preview, variables and arguments can be deleted using the context menu.
The following screenshot shows the variable and argument designer context menu.
Auto-surround with sequence
Since a workflow or certain container activities (such as NoPersistScope) can only contain a single root activity, adding a second activity required the developer to delete the first activity, add a Sequence activity, and then add both activities to the sequence activity. In .NET Framework 4.5 Developer Preview, a second activity can be added to a workflow or container activity. A sequence activity will be created automatically to contain the two activities.
The following screenshot shows the location to drop successive activities to automatically create a sequence activity.
The following screenshot shows the automatically created sequence activity.
Pan Mode
To more easily navigate a large workflow in the designer, pan mode can be enabled, allowing the developer to click and drag to move the visible portion of the workflow, rather than needing to use the scroll bars. The button to activate pan mode is in the lower right corner of the designer.
The following screenshot shows the pan button.
The middle mouse button or space bar can also be used to pan the workflow designer.
Multi-select
Multiple activities can be selected at one time, either by dragging a rectangle around them (when pan mode is not enabled), or by holding down Ctrl.
Multiple activity selections can also be dragged and dropped within the designer, and can also be interacted with using the context menu.
Outline view of workflow items
In order to make hierarchical workflows easier to navigate, components of a workflow are shown in a tree-style outline view. The outline view is displayed in the Document Outline view. Clicking on a node in outline view will navigate to the corresponding activity in the workflow designer, and the outline view will be updated to show activities that are selected in the designer.
The following screenshot of the completed workflow from the Getting Started Tutorial shows the outline view with a sequential workflow.
C# Expressions
Previously, all expressions in workflows used Visual Basic. In .NET Framework 4.5 Developer Preview, Visual Basic expressions are only used for projects created using Visual Basic. Visual C# projects now use C# for expressions. A fully functional C# expression editor is provided which capabilities such as grammar highlighting and intellisense. C# workflow projects created in previous versions that use Visual Basic expressions will continue to work.
As of Beta 1, C# expressions are validated at design-time. Errors in C# expressions will be marked with a red wavy underline.
More control of visibility of shell bar and header items
In a rehosted designer, some of the standard UI controls may not have meaning for a given workflow, and may be turned off. In .NET Framework 4, this customization is only supported by the shell bar at the bottom of the designer. In .NET Framework 4.5 Developer Preview, the visibility of shell header items at the top of the designer can be adjusted by setting WorkflowShellHeaderItemsVisibility with the appropriate ShellHeaderItemsVisibility value.
Auto-connect and auto-insert in Flowchart and State Machine workflows
Previously, connections between nodes in a Flowchart workflow had to be added manually. In .NET Framework 4.5 Developer Preview, flowchart and state machine nodes have auto-connect points that become visible when an activity is dragged from the toolbox onto the designer surface. Dropping an activity on one of these points adds the activity along with the necessary connection.
The following screenshot shows the attachment points that become visible when an activity is dragged from the toolbox.
Activities can also be dragged onto connections between flowchart nodes and states to auto-insert the node between two other nodes. The following screenshot shows the highlighted connecting line where activities can be dragged from the toolbox and dropped.
Designer Annotations
To facilitate developing larger workflows, the designer now supports adding annotations to help keep track of the design process. Annotation can be added to activities, states, flowchart nodes, variables and arguments. The following screenshot shows the context menu used to add annotations to the designer.
Debugging states
Previously, non-activity elements could not support debug breakpoints since they were not units of execution. This release provides a mechanism for adding breakpoints to State objects. When a breakpoint is set on a State, execution will break when the state is transitioned to, before its entry activities or triggers are scheduled.
Define and consume ActivityDelegate objects in the designer
Activities in WF4 used ActivityDelegate objects to expose execution points where other parts of the workflow could interact with a workflow's execution, but using these execution points usually required a fair amount of code. In this release, developers can define and consume activity delegates using the workflow designer. For more information, see How to: Define and consume activity delegates in the Workflow Designer.
Build-time validation
In .NET Framework 4, workflow validation errors weren’t counted as build errors during the build of a workflow project. This meant that building a workflow project could succeed even when there were workflow validation errors. In .NET Framework 4.5 Developer Preview, workflow validation errors cause the build to fail.
Design-time background validation
Previously, workflows were validated as a foreground process, which could potentially hang the UI during complex or time-consuming validation processes. Workflow validation now takes place on a background thread, so that the UI is not blocked.
View state located in a separate location in XAML files
In .NET Framework 4, the view state information for a workflow is stored across the XAML file in many different locations. This is inconvenient for developers who want to read XAML directly, or write code to remove the view state information. In .NET Framework 4.5 Developer Preview, the view state information in the XAML file is serialized as a separate element in the XAML file. Developers can easily locate and edit the view state information of an activity, or remove the view state altogether.
Expression extensibility
In .NET Framework 4.5 Developer Preview, we provide a way for developers to create their own expression and expression authoring experience that can be plugged into the workflow designer.
Opt-in for Workflow 4.5 features in rehosted designer
To preserve backward compatibility, some new features included in .NET Framework 4.5 Developer Preview are not enabled by default in the rehosted designer. This is to ensure that existing applications that use the rehosted designer are not broken by updating to the latest version. To enable new features in the rehosted designer, either set TargetFrameworkName to ".Net Framework 4.5", or set individual members of DesignerConfigurationService to enable individual features.
New Workflow Development Models
In addition to flowchart and sequential workflow development models, this release includes State Machine workflows, and contract-first workflow services.
State machine workflows
State machine workflows were introduced as part of the .NET Framework 4.0.1 in the Microsoft .NET Framework 4 Platform Update 1. This update included several new classes and activities which allowed developers to create state machine workflows. These classes and activities have been updated for .NET Framework 4.5 Developer Preview. Updates include the ability to set breakpoints on states, the ability to copy and paste transitions in the workflow designer, and designer support for shared trigger transition creation. The StateMachine activity, along with State, Transition, and other activities can be used to build state machine workflows. The following screenshot shows the completed state machine workflow from the Getting Started Tutorial step How to: Create a State Machine Workflow.
For more information on creating state machine workflows, see State Machine Workflows.
Contract-first workflow development
The contract-first workflow development tool allows the developer to design a contract in code first, then, with a few clicks in Visual Studio, automatically generate an activity template in the toolbox representing each operation. These activities are then used to create a workflow that implements the operations defined by the contract. The workflow designer will validate the workflow service to ensure that these operations are implemented and the signature of the workflow matches the contract signature. The developer can also associate a workflow service with a collection of implemented contracts. For more information on contract-first workflow service development, see How to: Create a workflow service that consumes an existing service contract.