ebook img

Foundations of WF: an Introduction to Windows Workflow Foundation PDF

259 Pages·2006·8.076 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Foundations of WF: an Introduction to Windows Workflow Foundation

CYAN YELLOW MAGENTA BLACK PANTONE 123 CV BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN.NET Companion eBook Available Foundations of WF: An Introduction to Windows Workflow Foundation F o Dear Reader, u Foundations of n Have you ever spent hours coding workflow for your applications? If so, the new d Microsoft Windows Workflow Foundation (WF) technology will make your life easier. I’ve written lots of workflow code over the years, so I can tell you from a WF Author of experience that WF makes writing workflow code much easier. t i Beginning Object-Oriented In this book, you’ll discover the power of WF. You’ll learn about all the prebuild o ASP.NET 2.0 with VB.NET activities you can include in your workflow, along with how to create your own n activities. WF is fully extensible and allows you an unlimited number of options s for your workflow. You’ll also learn how to use workflow activities to retrieve o data, and finally, how to tie an ASP.NET application with a workflow built in WF. f This book, unlike most of the Microsoft WF samples, has code in both VB .NET and C#. All the examples—and there are many—have VB .NET code, and many W have the accompanying C# code. This book will allow you to begin creating new workflow applications easily in either VB .NET or C#. Each chapter includes an introduction to one or more activities that make up WF, along with examples of F how to use each activity. Many chapters include a final section providing a real- world example (a purchase order system). This book will have you using WF to create workflow applications with VB .NET or C# in a short amount of time. I hope you enjoy this new technology as much as I do. Brian R. Myers, MCSD An Introduction to Windows Workflow Foundation Join online discussions: THE APRESS ROADMAP blogs.apress.com Foundations of WF: Pro WF: An Introduction to Companion eBook Windows Workflow Foundation Windows Workflow in .NET 3.0 Learn how to take advantage of workflow to streamline your applications and their use See last page for details on $10 eBook version Brian R. Myers ISBN 1-59059-718-4 SOURCECODEONLINE 53499 M www.apress.com y e r s US $34.99 Shelve in .NET 6 89253 59718 7 9 781590 597187 User level: Beginner–Intermediate this print for content only—size & color not accurate spine = 0.62" 264 page count Myers_718-4FRONT.fm Page i Monday, September 25, 2006 6:55 AM Foundations of WF An Introduction to Windows Workflow Foundation ■ ■ ■ Brian R. Myers Myers_718-4FRONT.fm Page ii Monday, September 25, 2006 6:55 AM Foundations of WF: An Introduction to Windows Workflow Foundation Copyright © 2007 by Brian R. Myers All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-718-7 ISBN-10 (pbk): 1-59059-718-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Jonathan Hassell Technical Reviewer: Jim Flanagan Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Tracy Brown Collins Copy Edit Manager: Nicole Flores Copy Editor: Susannah Pfalzer Assistant Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Susan Glinert Proofreader: Nancy Sixsmith Indexer: Becky Hornyak Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Code/Download section. Myers_718-4FRONT.fm Page iii Monday, September 25, 2006 6:55 AM To my nieces (Erica, Natalie, and Sarah) and nephews (Ryan and Aaron)— there is no limit to what you can achieve Myers_718-4FRONT.fm Page iv Monday, September 25, 2006 6:55 AM Myers_718-4FRONT.fm Page v Monday, September 25, 2006 6:55 AM Contents at a Glance About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii ■ CHAPTER 1 Introduction to Workflow and Windows Workflow Foundation . . . 1 ■ CHAPTER 2 First Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ■ CHAPTER 3 Conditional Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 ■ CHAPTER 4 Flow Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 ■ CHAPTER 5 Rules-Based Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 ■ CHAPTER 6 Workflow and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 ■ CHAPTER 7 Interacting with Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 ■ CHAPTER 8 Custom Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 ■ CHAPTER 9 Deploying Workflow Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 ■ CHAPTER 10 Employee Performance Review Application . . . . . . . . . . . . . . . . . . 173 ■ CHAPTER 11 Integration with Office 2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 ■ INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 v Myers_718-4FRONT.fm Page vi Monday, September 25, 2006 6:55 AM Myers_718-4FRONT.fm Page vii Monday, September 25, 2006 6:55 AM Contents About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii ■ CHAPTER 1 Introduction to Workflow and Windows Workflow Foundation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What Is Workflow? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 When to Use Which Workflow Type . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Why Use Workflows? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Introducing Windows Workflow Foundation . . . . . . . . . . . . . . . . . . . . . . . . 3 Architecture of Windows Workflow Foundation . . . . . . . . . . . . . . . . . . . . . . 3 Getting Started with WF and VS2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Out-of-the-Box Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 ■ CHAPTER 2 First Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Workflow and Activities As Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Workflow Code in VB .NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Workflow Code in C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 First Workflow in VB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Sequential Workflow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Passing Parameters to VB .NET Workflow. . . . . . . . . . . . . . . . . . . . . 24 State Machine Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 First Workflow in C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Code Differences Between VB and C#. . . . . . . . . . . . . . . . . . . . . . . . 31 Passing Parameters to C# Workflow . . . . . . . . . . . . . . . . . . . . . . . . . 33 Real-World Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 vii Myers_718-4FRONT.fm Page viii Monday, September 25, 2006 6:55 AM viii ■ CONTENTS ■ CHAPTER 3 Conditional Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 IfElse Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 IfElse Activity Within Sequential Workflow. . . . . . . . . . . . . . . . . . . . . 43 IfElse Activity Within State Machine Workflow . . . . . . . . . . . . . . . . . 49 While Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 While Activity Within Sequential Workflow . . . . . . . . . . . . . . . . . . . . 53 While Activity Within State Machine Workflow . . . . . . . . . . . . . . . . . 54 Conditional Activity Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Conditional Activity Group Within Sequential Workflow. . . . . . . . . . 55 Conditional Activity Group Within State Machine Workflow. . . . . . . 57 Real-World Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 ■ CHAPTER 4 Flow Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 State Machine–Specific Control Activities . . . . . . . . . . . . . . . . . . . . . . . . . 67 State-Related Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Delay, Suspend, and Terminate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Delay, Suspend, and Terminate in VB . . . . . . . . . . . . . . . . . . . . . . . . 71 Delay, Suspend, and Terminate in C# . . . . . . . . . . . . . . . . . . . . . . . . 79 Sequence and Parallel Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Sequence Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 State Machine Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 EventDriven Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Real-World Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 ■ CHAPTER 5 Rules-Based Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Rules in WF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Rules and the Policy Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Sequential Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Full Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Real-World Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Myers_718-4FRONT.fm Page ix Monday, September 25, 2006 6:55 AM ■ CONTENTS ix ■ CHAPTER 6 Workflow and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 InvokeWebService Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Workflow As Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 ■ CHAPTER 7 Interacting with Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Workflow Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 CallExternalMethod Activity in VB. . . . . . . . . . . . . . . . . . . . . . . . . . . 117 CallExternalMethod Activity in C#. . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Events in VB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Events in C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Workflow Fault Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Transaction Scope and Compensate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 ■ CHAPTER 8 Custom Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Basics of a Custom Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Creating a New Activity from the Activity Class . . . . . . . . . . . . . . . . . . . 141 Example in VB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Example in C#. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Real-World Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 ■ CHAPTER 9 Deploying Workflow Applications . . . . . . . . . . . . . . . . . . . . . . . 163 Deployment Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Real-World Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 ClickOnce Deployment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 SQLPersistenceService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Implementing Persistence in VB. . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Implementing Persistence in C#. . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.