Tech Brief

Windows Workflow Foundation

Should you code your business logic or use a workflow model?

Windows Workflow Foundation (WF) provides the programming model, engine and tools for quickly building workflow-enabled applications on Windows. It comprises a new .NET Framework namespace called System.Workflow, an in-process workflow engine and workflow designers for Visual Studio 2005 and Visual Studio 2008 ("Orcas").

WF provides full support for Visual Basic.NET and C#, debugging and a graphical workflow designer. You can develop your workflow completely in code or as declarative XML (XAML). It provides an extensible model and designer to build custom activities that encapsulate workflow functionality for end users or for reuse across multiple projects. It runs on both Windows clients (XP and Vista) and Windows Servers (2003 and 2008).

WF includes the base support required for both system and human workflow across a wide range of scenarios involving long-running, frequently changing or tracked business logic. It can also be applied to software patterns from Service-Oriented Architecture (SOA) to simple-state machines and to utility functions such as user interface page flow.

When to Use Workflow
Workflow development is a natural progression from writing code. But many developers are uncertain about when to use a workflow runtime instead of just writing code for business logic. It's a good question because it's possible to develop all of your business logic in code. However, using a workflow runtime offers some major benefits in certain scenarios.

The first scenario is when you have long-running business logic. Code is naturally short running, and if you want to do anything that takes any time at all you have to think about storing state and how to pick it up again later. When you translate a long running process into code you have to write several distinct methods in code that act as atomic blocks of the process. Properly designed procedural code can't just wait for a response and extra code must be written to deal with the state and any message correlation once the event being waited on is received.

Using a workflow solves the long-running logic problem by modeling the process at a slightly higher level than directly in code. You still have to write code but the state management, persistence and correlation of incoming messages is provided by the workflow runtime.

The second scenario is if the business logic or business rules governing the process change frequently. This is evident if you have logic or rules changes more frequently than you're able to deploy new compiled code. Each customer of a line-of-business software vendor has its own unique requirements for the business-logic implementation and often a long period of customization before the software can be used by the customer.

Using a workflow provides a model in which a set of activities can be built in code, and the order of execution of those activities and the properties on those activities can be customized for an individual customer easily in the WF designer.

The software is still built primarily in code, but customization of the model for a new customer-or for a customer that requests changes frequently-becomes much easier. Since the workflow model can be stored in XML, using a workflow allows for a scenario in which business logic implemented as a workflow model, or as a set of rules, can be changed while the application is executing.

WF Services
The third scenario is if visibility into business-logic execution or the business-logic model is required. Once you decide to build your business logic as a workflow model, you can take advantage of WF services. These services include ACID transactions, compensating actions, exception management and process tracking. The tracking service provides visibility into executing workflow instances and, like other services, it's something that can be applied to the workflow runtime without adding extra code.

You also gain visibility into the workflow model simply because you can view a workflow model in the workflow designer, and you can print it out or take a copy of the image for inclusion in a functional specification. This can be valuable in explaining the software to non-developers, or it could be useful documentation for when a software design needs to be learned by others and modified later.

Built on WF
WF will be used across many future Microsoft products including the 2007 Office system, the Dynamics product line and the next major version of BizTalk Server.

Finally, workflow provides a way of describing the order of execution and dependent relationships between pieces of short- or long-running work. A workflow model can be executed inside any Windows process that hosts the .NET Framework, including console apps, forms-based apps, Windows Services, ASP.NET Web sites and Web Services.
comments powered by Disqus

Featured

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

Subscribe on YouTube