First Look at Workflow in .NET 4

First Look at Workflow in .NET 4

  • Comments 2

.net windows workflow foundation bl Windows Workflow Foundation programs coordinate with a minimal ceremony. It provides a programming model, in-process workflow engine and rehostable designer to implement long-running processes as workflows within .NET applications.

In .NET Framework 4, Windows Workflow Foundation introduces a significant amount of change from the previous versions in .NET 3.0 and 3.5.  In fact, the team revisited the core of the programming model, runtime and tooling and has re-architected each one to increase performance and productivity. And they addressed important feedback garnered from customer engagements using the previous versions.

When to Use Workflow

It’s useful to think about different kinds of applications that might use workflows

  • Any application that implements a long-running process is a natural for workflow.
  • An ASP.NET application that displays pages to its users might use a workflow to control the order in which those pages are shown.
  • A composite application in a service-oriented environment might implement its core behavior using a workflow.
  • An application targeting a specific problem, such as customer relationship management (CRM), or a specific vertical market, such as financial services, might be built around a workflow.

For ISVs, Workflows can help you provide the ability for users to customize what your application does without a major intrusion into your functionality. You can empower your users:

  • To make decisions based on their own (changing) business rules.
  • Ways to communicate with other software and other systems outside the workflow.
  • Ways to interact with people.
  • The ability to maintain state throughout the workflow’s lifetime.

What’s New in .NET 4 Workflows

workflowartIn the .NET Framework 4, there have been significant enhancements in the Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) frameworks. .NET developers can use these technologies, either independently or together, to eliminate the tradeoff between ease of service authoring and performant, scalable services.

Workflow in .NET is comprised of Activities, Runtime, Tooling. Here’s a summary of the important changes to .NET 4 Workflows.

XAML-only workflows are the new default

A declarative workflow can be made within a XAML file with no code-behind. This means that workflows can be stored, retrieved, and altered as data.

Unified model between WF, WCF, and WPF

As developers, we need the same power and flexibility of a declarative programming model for the internals of an application as we have for the user interface in Windows Presentation Foundation (WPF). Windows Workflow Foundation (WF) provides the declarative framework for building application and service logic and gives developers a higher level language for handling asynchronous, parallel tasks and other complex processing.

Extended base activity library

In .NET 4 you get new activities:

    • Flow control: Flowchart, ForEach, DoWhile, Break
    • WCF: Send, Receive, SendReceive, RecieveParameters, CorrelationScope, InitializeCorrelation
    • Others: Assign, MethodInvoke, Persist, Interop, PowerShellCommand
    • More are planned to be released on CodePlex.
Simplified WF programming model

WF 4.0 makes it much easier to:

    • Host workflows and run workflow instances
    • Manage workflow bookmarks
    • Create custom activities
    • Managing data and arguments

Activity is the core base type in the programming model and represents both workflows and activities.  In addition, you no longer need to create a WorkflowRuntime to invoke a workflow. You can simply create an instance and execute it, simplifying unit testing and application scenarios where you do not want to go through the trouble of setting up a specific environment. 

The workflow  programming model becomes a fully declarative composition of activities, with no code-beside, simplifying workflow authoring.

Support for arguments, variables, expressions

Flowing data across activities is challenging. It requires dependency properties and data binding. It feels unnatural to most developers.

In addition, managing activity state is also challenging; there was no way to define local storage in XAML

WF 4.0 simplifies data flow by adding arguments, variables, and expressions.

Major improvements to WCF integration

New messaging activities, message correlation, and improved hosting support, along with fully declarative service definition are the major areas of improvement.

You can think "WCF on the outside, WF on the inside". WCF exposes external interface while WF describes internal flow & state transitions.

When sending and receiving WCF messages, correlation is a common need. In .NET 3.5 correlates based on context headers, while .NET 4.0 adds correlation support to WCF. WF makes correlation easy to use via activities

    • XPath expressions identify a correlation token
    • CorrelationScope
    • InitializeCorrelation
Runtime and designer improvements

The designer now supports the ability to work with much larger workflows without a degradation in performance and designers are all based on Windows Presentation Foundation (WPF), taking full advantage of the rich user experience one can build with the declarative UI framework.  Activity developers will use XAML to define the way their activities look and interact with users in a visual design environment.  In addition, rehosting the workflow designer in your own applications to enable non-developers to view and interact with your workflows is now much easier.

Hosting & management via AppFabric

AppFabric, formerly known as Code Name "Dublin", provides WF hosting & management extensions to IIS and WAS.

Windows Server AppFabric has three core capabilities:  caching, workflow management and service management.

  • For Web applications, Windows Server AppFabric provides caching capabilities to provide high-speed access, scale, and high availability to application data thereby avoiding unnecessary calls to the data source.

  • For composite applications, Windows Server AppFabric makes it easier to build and manage services built using Windows Workflow Foundation and Windows Communication Foundation.

  • In general, customers  who have applications composed of services, web, data, and legacy components will find that  Windows Server AppFabric makes it simpler to develop, deploy, and manage these composite applications.

For more information and to try out AppFabric, see Windows Server AppFabric.

flowchartFlowcharts

Flowcharts offer a middle ground between the sequential and state machine models. You get:

  • Simple step-by-step model, with decisions and switches
  • Allows you to return to previous activities in the workflow

The Flowchart more closely resembles the concepts and thought processes that many analysts and developers go through when creating solutions or designing business processes.  Therefore, it made sense to provide an activity to make it easy to model the conceptual thinking and planning that had already been done.  The Flowchart enables concepts such as returning to previous steps and splitting logic based on a single condition, or a Switch / Case logic.

Creating Custom Activities

.NET 4.0 re-factors the programming model for creating custom activities. Derive your custom activity from WorkflowElement to creating custom activities from scratch. Derive from Activity to create custom activities from other Activities.

In First Look at .NET 4 Workflow -- Part 2, I’ll walk you through the concepts of a basic workflow. You can try out a hands on lab using the Visual Studio 2010 and .NET Framework 4 Training Kit.

Using .NET 3.X Workflows

Your 3.x workflows will continue to work using the WF 3.0 runtime. And you can use 3.x activities in a 4.0 workflow using use the .NET 4 Interop activity. Guidance will be coming soon for how to prepare your 3.x applications.

Resources

For an overview of how workflows can integrate into your application, see  Business Process & Workflow video from MSDEV.

Hands on Lab

I recommend you try out the hands on lab that’s part of the Visual Studio 2010 and .NET Framework 4 Training Kit.

In the lab you will get to know the basics of creating, hosting and running a workflow. This lab is also intended to be an introduction to the new workflow authoring constructs in the .NET Framework 4 and Visual Studio 2010, including the new Workflow Designer, expressions, variables and arguments. Additionally, you will explore the use of some basic built-in activities.

In this Hands-On Lab, you will learn:

  • How to create a sequential workflow using the designer and XAML or, alternatively, using plain C# or Visual Basic code
  • How to run and test the sequential workflow using the WorkflowApplication and WorkflowInvoker classes
  • How to pass InArguments and receive OutArguments from a workflow
  • How Expressions and Variables are used
  • How to use the WriteLine, If, TryCatch, Catch<T> and Throw activities
  • How to load and run an activity from a .xaml file
  • How to create an activity designer
  • How to host the WorkflowDesigner in your own application

Bruce D. Kyle
ISV Architect Evangelist | Microsoft Corporation

cid:image010.png@01C9DEED.1FDB2200 cid:image011.png@01C9DEED.1FDB2200 cid:image012.gif@01C9DEED.1FDB2200 channel9

Special thanks to Ron Jacobs, Senior Technical Evangelist

Add to Technorati Favorites

Bookmark and Share



Page 1 of 1 (2 items)
Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post