image

I started working with Windows Workflow Foundation (WF) in 2006 during the early beta and Community Technology Preview (CTP) stages. WF became a shipping Microsoft product named .NET Framework 3.0 in November 2006 along with Windows Presentation Foundation (WPF) and Windows Communication Foundation (WCF). I actually started to learn and use all three of these foundations at the same time in my day job.

While I was impressed with the flexibility and capabilities of WPF and WCF, I was somehow inexplicably drawn to Windows Workflow Foundation (WF). WF isn’t just a new way to implement a user interface or a new way to communicate between applications and services. WF represents a completely new way to develop applications. It is declarative, visual, and infinitely flexible. It promotes a model that cleanly separates what to do from when to do it. This separation allows you to change the when without affecting the what. Business logic is implemented as a set of discrete, testable components that are assembled into workflows like building blocks.

Workflow isn’t a new concept. But when Microsoft spends years developing a workflow foundation and provides it to us without cost, it is an event worth noting. Other workflow frameworks exist, but since it is included in the .NET Framework, WF is the de facto standard workflow framework for Windows applications.

This is the third edition of this book. The first two editions targeted the version of WF that shipped with the .NET Framework 3.0 and 3.5, respectively. This book targets the all-new version 4 of WF, which has been completely redesigned and rewritten. If you are using the 3.x version of WF, this is not the book for you—you need my book Pro WF: Windows Workflow in .NET 3.5, also published by Apress.

I originally wrote the first edition of this book because I was excited about WF. I was excited about the opportunities that it held for application developers like us. I’m even more excited today, since Microsoft has listened to the feedback and given us a completely new and greatly improved workflow framework.

My hope is that this book will help you use WF to build an exciting new generation of workflow-enabled applications.

Who Should Read This Book

This book is for all .NET developers who want to learn how to use Windows Workflow Foundation version 4 in their own applications. This book is not a primer on .NET or the C# language. To get the most out of the examples that I present in this book, you need a good working knowledge of the .NET Framework. All of the examples are presented in C#, so you should be proficient with C#.

An Overview of This Book

The material in this book is a WF 4 tutorial presented in 18 chapters, with each chapter building upon the ones before it. I’ve tried to organize the material so that you don’t have to jump ahead in order to understand how something works. But since the chapters build upon each other, I do assume that you have read each chapter in order and understand the material that has already been presented.

The short sections that follow provide a brief summary of each chapter.

Chapter 1: A Quick Tour of Windows Workflow Foundation

This chapter provides a brief introduction to WF. In this chapter, you jump right in and develop your first workflow ("Hello Workflow"). You are introduced to some of the fundamental concepts of WF, such as how to pass parameters to a workflow and how to make decisions within a workflow.

Chapter 2: Foundation Overview

The goal of this chapter is to provide a high-level overview of WF in its entirety. This chapter doesn’t teach you how to use each individual WF feature, but it does acquaint you with the design-time and runtime features that are available with WF. This chapter is a road map for the material that is covered in the remainder of the book.

Chapter 3: Activities

Activities are the building blocks of WF and where you place the business logic that is specific to your particular problem domain. In this chapter, you will learn how to develop your own custom activities using the base classes that ship with WF. This chapter also provides a high-level review of the standard activities that are provided with WF.

Chapter 4: Workflow Hosting

WF is not a stand-alone application. It is a framework for building your own workflow-enabled applications. This chapter demonstrates how to host and execute workflows in your own application. It describes how to use each of the hosting classes that are supplied with WF.

Chapter 5: Procedural Flow Control

WF includes support for two different workflow modeling styles out of the box: procedural and flowchart. The modeling style determines how the flow of control between individual activities is modeled. The focus of this chapter is the procedural modeling style. It uses familiar programming constructs to control the flow of execution.

Chapter 6: Collection-Related Activities

This chapter focuses on the activities that enable you to work with collections of data. WF includes standard activities that iterates over each element in a collection, executing the same activity for each element. Also included in WF are a set of activities that allow you to manipulate collections, adding and removing elements and so on.

Chapter 7: Flowchart Modeling Style

The other workflow modeling style that is supported by WF is the flowchart modeling style. This style of modeling workflows enables you to use direct links between activities to control the flow of execution. In this chapter, I review the activities that are provided with WF to support this modeling style. After explaining how to model a workflow using this style, I revisit several examples that were presented in earlier chapters. This is done to contrast how the two modeling styles (procedural and flowchart) can be used to solve similar business problems.

Chapter 8: Host Communication

This chapter focuses on direct communication between the host application and a workflow instance. The chapter provides an overview of long-running workflows and the bookmark mechanism used to implement them. The use of workflow extensions for sending data to a host application is also discussed. The classes that support a general-purpose callback mechanism are also demonstrated.

Chapter 9: Workflow Services

This chapter focuses on the Windows Communication Foundation (WCF) support that is provided with WF. Included with this support is the ability to declaratively author WCF services using WF as well as to invoke WCF services from within a workflow.

Chapter 10: Workflow Services Advanced Topics

This chapter continues coverage of the WCF support that is provided by WF. The chapter expands on this basic example from Chapter 9 by implementing additional workflow services that are consumed by the original workflow. Context-based and Content-based correlation is demonstrated, along with the duplex message exchange pattern. The chapter concludes with a discussion of exception and fault processing, flowing transactions into a workflow service, and the use of standard WF behaviors to fine-tune workflow service performance.

Chapter 11: Workflow Persistence

An important capability of WF is the ability to persist workflow instances (save and reload them at a later time). The chapter focuses on how to enable workflow persistence in your applications. The built-in support for persistence to a SQL Server database is demonstrated in this chapter.

Chapter 12: Customizing Workflow Persistence

This chapter focuses on ways to extend or customize workflow persistence and continues the discussion that began in Chapter 11. The chapter also provides an example that implements a custom instance store that persists workflow instances to the file system rather than to a database.

Chapter 13: Transactions, Compensation, and Exception Handling

This chapter focuses on the mechanisms provided by WF to support the handling of exceptions and to ensure the consistency of work that is performed within a workflow. Exception handling techniques, transactions and compensation are all demonstrated.

Chapter 14: Workflow Tracking

Workflow tracking is a built-in mechanism that automatically instruments your workflows. By simply adding a tracking participant to the workflow runtime, you are able to track and record status and event data related to each workflow and each activity within a workflow. This chapter shows you how to use the built-in support for tracking and how to use tracking profiles to filter the type of tracking data that is produced. The chapter also demonstrates how to develop your own custom tracking participants to process the tracking data.

Chapter 15: Enhancing the Design Experience

In this chapter, you learn how to create custom activity designers. These designer components provide the visible representation of an activity on the workflow designer canvas. The chapter also demonstrates several ways to implement validation logic for activities.

Chapter 16: Advanced Custom Activities

This chapter focuses on several advanced custom activity scenarios. Most of these scenarios are related to the execution of one or more children. The chapter demonstrates how to develop your own custom activities that execute one or more child activities or invoke a callback delegate. Also demonstrated are the techniques for providing the metadata that WF requires for each activity. The chapter concludes with an example that demonstrates the use of execution properties and bookmark options.

Chapter 17: Hosting the Workflow Designer

The workflow designer is not limited to use only within the Visual Studio environment. WF provides the classes necessary to host this same designer within your applications. This chapter is all about hosting this designer. After a brief overview of the major workflow designer components, you will implement a simple application that hosts the workflow designer. In subsequent sections, you will build upon the application, adding new functionality with each section.

Chapter 18: WF 3.x Interop and Migration

This chapter focuses on strategies for dealing with existing WF 3.0 or 3.5 applications (WF 3.x). The chapter begins with an overview of the migration strategies that are available to you followed by a demonstration of the Interop activity. This activity enables you to execute some WF 3.x activities within the WF 4 runtime environment.

Appendix A: Glossary

This is a glossary of commonly used WF terms.

Appendix B: Comparing WF 3.x to WF 4

This appendix highlights major differences between the previous version of WF (3.x) and WF 4.

What You Need to Use This Book

To execute the examples presented in this book, you’ll need to install a minimum set of software components on a supported OS. The minimum requirements are the following:

  • Visual Studio 2010 Professional, Premium, or Ultimate.
  • The .NET 4 runtime (installed with Visual Studio 2010).
  • SQL Server 2005 or 2008 Express edition. If you have one of the full licensed versions of SQL Server, that will work fine. SQL Server 2008 Express is installed with Visual Studio 2010.

Check with Microsoft for a current list of supported operating systems. The Microsoft .NET Framework Development Center (http://msdn.microsoft.com/en-us/netframework/default.aspx) is a good starting point to locate any miscellaneous files that you need.

Obtaining This Book’s Source Code

I have found that the best way to learn and retain a new skill is through hands-on examples. For this reason, this book contains a lot of example source code. I’ve been frustrated on more than one occasion with technical books that don’t print all of the source code in the book. The code may be available for download, but then you need to have a computer handy while you are reading the book. That doesn’t work well at the beach. So, I’ve made it a point to present all of the code that is necessary to actually build and execute the examples.

When you are ready to execute the example code, you don’t have to enter it yourself. You can download all of the code presented in this book from the Apress site at www.apress.com; go to the Source Code/Download section to find it. I’ve organized all of the downloadable code into separate folders and Visual Studio solutions for each chapter. I suggest that you use the same approach as you work through the examples in this book.

How to Reach Me

If you have questions or comments about this book or Windows Workflow, I’d love to hear from you. Just send your email to [email protected]. To make sure your mail makes it past any spam filters, you might want to include the text ProWF4 somewhere in the subject line.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.108