ebook img

Microsoft Press Windows Workflow Foundation Step By Step PDF

486 Pages·2007·8.088 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 Microsoft Press Windows Workflow Foundation Step By Step

PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2007 by Kenn Scribner All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number: 2006940677 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWE 2 1 0 9 8 7 Distributed in Canada by H.B. Fenn and Company Ltd. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further infor- mation about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected]. Microsoft, Microsoft Press, Active Directory, ActiveX, BizTalk, DataTips, Developer Studio, FrontPage, IntelliSense, Internet Explorer, Jscript, MSDN, MSN, SQL Server, Visual Basic, Visual C#, Visual C++, Visual SourceSafe, Visual Studio, Visual Web Developer, Win32, Windows, Windows NT, Windows Server, Windows Vista, and WinFX are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Ben Ryan Project Editor: Lynn Finnel Copy Editor: Roger LeBlanc Technical Reviewer: Kurt Meyer Peer Reviewer: Scott Seely Editorial and Production Services: Waypoint Press Body Part No. X12-64035 To my wonderful family, Judi, Aaron, and Katie, without whose love and support life has little meaning. Thank you all for always being there. iii Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .v Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv Part I Introducing Windows Workflow Foundation (WF) 1 Introducing Microsoft Windows Workflow Foundation. . . . . . . . . . . . . . 3 Workflow Concepts and Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Enter the Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 Multithreading and Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 Comparing WF with Microsoft BizTalk and WCF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Beginning Programming with WF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Visual Studio Workflow Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 Building Your First Workflow Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 Chapter 1 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 2 The Workflow Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Hosting WF in Your Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 A Closer Look at the WorkflowRuntime Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 Building a Workflow Runtime Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28 Starting the Workflow Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31 Stopping the Workflow Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 Subscribing to Workflow Runtime Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34 Chapter 2 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38 3 Workflow Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Introducing the WorkflowInstance Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41 Starting a Workflow Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: www.microsoft.com/learning/booksurvey/ v vi Table of Contents Starting a Workflow Instance with Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Determining Workflow Instance Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Terminating a Workflow Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Dehydration and Rehydration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Chapter 3 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4 Introduction to Activities and Workflow Types. . . . . . . . . . . . . . . . . . . . 57 Introducing the Activity, the Basic Unit of Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 The ActivityExecutionContext Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Dependency Properties 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Activity Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Workflow Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Selecting a Workflow Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 The Sequence Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Building a Sequential Workflow Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 The State Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Building a State Machine Workflow Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Chapter 4 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 5 Workflow Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Pluggable Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Workflow Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Workflow Event Tracking Using SqlTrackingService . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Setting Up SQL Server for Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Using the SqlTrackingService Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Tracking User Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Building Custom Tracking Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Viewing Tracking Information with WorkflowMonitor . . . . . . . . . . . . . . . . . . . . . . . . 96 Chapter 5 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 6 Loading and Unloading Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Persisting Workflow Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Setting Up SQL Server for Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Introducing the SqlWorkflowPersistenceService Service . . . . . . . . . . . . . . . . . . . . . . 106 Unloading Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Loading Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Loading and Unloading Instances on Idle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Chapter 6 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Table of Contents vii Part II Working with Activities 7 Basic Activity Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Using the Sequence Activity Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127 Using the Code Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 Using the Throw Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 Using the FaultHandler Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137 Quick Tour of the Workflow Visual Designer . . . . . . . . . . . . . . . . . . . . . . . . . . .138 Using the Suspend Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145 Using the Terminate Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148 Chapter 7 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150 8 Calling External Methods and Workflows. . . . . . . . . . . . . . . . . . . . . . . . 151 Building an ExternalDataService Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152 Workflow Intraprocess Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152 Designing and Implementing Workflow Intraprocess Communication . . . .153 The Motor Vehicle Data-Checking Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154 Creating Service Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156 Using the ExternalDataExchange Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157 Using ExternalDataEventArgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159 Creating External Data Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .160 The CallExternalMethod Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .170 Creating and Using Custom External Data Service Activities . . . . . . . . . . . . . . . . . .170 Receiving Workflow Data Within the Host Application . . . . . . . . . . . . . . . . . . . . . . .174 Invoking External Workflows with InvokeWorkflow . . . . . . . . . . . . . . . . . . . . . . . . . .177 Chapter 8 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .181 9 Logic Flow Activities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Conditions and Condition Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183 The Questioner Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184 Using the IfElse Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .185 Using the While Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .195 Using the Replicator Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199 Chapter 9 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .208 10 Event Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Using the HandleExternalEvent Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209 Using the Delay Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .211 Using the EventDriven Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .212 viii Table of Contents Using the Listen Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Using the EventHandlingScope Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Host-to-Workflow Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Creating the Communication Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Chapter 10 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 11 Parallel Activities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Using the Parallel Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Using the SynchronizationScope Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Using the ConditionedActivityGroup (CAG) Activity . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Chapter 11 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 12 Policy and Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Policy and Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Implementing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Rule Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 The Update Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Rule Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 Forward Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Implicit Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Attributed Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Explicit Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Controlling Forward Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Controlling Rule Reevaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 Using the Policy Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Chapter 12 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 13 Crafting Custom Activities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 More About Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Activity Virtual Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Activity Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Execution Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Activity Lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Creating an FTP Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Creating a Custom ActivityValidator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Providing a Toolbox Bitmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Tailoring Activity Appearance in the Visual Workflow Designer . . . . . . . . . . . . . . . 315 Integrating Custom Activities into the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 Chapter 13 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Table of Contents ix Part III Workflow Processing 14 State-Based Workflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 The State Machine Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .327 Using the State Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328 Using the SetState Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328 Using the StateInitialization Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329 Using the StateFinalization Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .330 Creating a State-Based Workflow Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .330 Chapter 14 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .346 15 Workflows and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 Understanding Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .347 Classic (XA) Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .348 Initiating Transactions in Your Workflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .351 Workflow Runtime and Transactional Services . . . . . . . . . . . . . . . . . . . . . . . . .351 Fault Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .352 Ambient Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .352 Using the TransactionScope Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .352 Committing Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353 Rolling Back Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .354 Using the CompensatableTransactionScope Activity . . . . . . . . . . . . . . . . . . . . . . . . . .354 Using the Compensate Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .355 Using the CompensatableSequence Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .356 Creating a Transacted Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .357 Chapter 15 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .371 16 Declarative Workflows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 Declarative Workflow—XML Markup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .374 Declaring Namespaces and Namespace Association . . . . . . . . . . . . . . . . . . . . . . . . .375 Creating and Executing XAML-Based Workflows . . . . . . . . . . . . . . . . . . . . . . . . . . . .377 Chapter 16 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .390 17 Correlation and Local Host Communication. . . . . . . . . . . . . . . . . . . . . . 391 Host and Workflow Local Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .391 Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392 The CorrelationParameter Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .394 The CorrelationInitializer Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .394 x Table of Contents The CorrelationAlias Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Building Correlated Workflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Chapter 17 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 18 Invoking Web Services from Within Your Workflows. . . . . . . . . . . . . . 431 Web Services Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Using the InvokeWebService Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 Adding the Web Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 Configuring the Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Static Proxy Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Dynamic Proxy Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Working with Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 Long-Running XML Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Building a Workflow That Uses an XML Web Service . . . . . . . . . . . . . . . . . . . . . . . . 438 Chapter 18 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 19 Workflows as Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 Exposing a Workflow as an XML Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 Creating the Workflow Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 Configuring Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 Workflow Housekeeping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 Using the WebServiceInput Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Using the WebServiceOutput Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Using the WebServiceFault Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Creating a Host Web Service Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Chapter 19 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: www.microsoft.com/learning/booksurvey/ Foreword To me, workflow engines such as Microsoft BizTalk always seemed like a really expensive thing that I didn't need for many projects. I always thought, “How hard can it be to actually code the logic you draw on the screen?” As a result, I spent a lot of time not learning what a workflow engine could do for me and, instead, lived with “just code.” Still, I was intrigued and would bug my friends about what they saw as the value of BizTalk. They would usually get me excited enough to try installing the product and learning how it worked. Every time I tried to make the plunge and learn how to use BizTalk, I backed away because it seemed too complex for what I perceived as a flowchart execution engine. Sometime around 2003, while working at Microsoft on what was to become Windows Communication Foundation, I heard about a general-purpose workflow engine being built within Microsoft. Rumor had it that the workflow engine might even be integrated into the operating system! The reason: Prior to then, groups within Microsoft had created their own workflow engines for their own problem domains. Most of the engines were written in C++ and exhibited limited flexibility outside of their domain area. BizTalk, which had a general- purpose engine, was not then designed to have its engine separated from the BizTalk product. What Microsoft discovered was there was a real need for a single, general-purpose workflow engine so that internal Microsoft teams could stop reinventing workflow. This realization (which occurred prior to me hearing anything) helped create what would eventually become the Windows Workflow Foundation team. As a part of .NET Frameworks 3.0, Windows Workflow Foundation is a freely distributable .NET component. On Windows Vista and later, it ships as a part of the operating system. What doesthis mean for developers? It means that they can learn how to use a workflow engine and distribute their applications while being able to rely on a workflow engine just being present on the client machine. Bigger applications will still need tools such as BizTalk Server to manage workflows. But, for smaller applications that could use some of the benefits of workflow (such as state machines and the ability to suspend and resume a workflow), Windows Workflow Foundation is a godsend. The book you now hold shows all the little things that Windows Workflow Foundation can do. Because it is the introductory book to Windows Workflow Foundation, it takes a tour of the feature set and lets you know what is available. For me, this book has served as a great introduction to the technology. I have discovered that most projects would benefit from a healthy dose of workflow somewhere. Thesamples in this book proved as much to me. Kenn, congratulations on finishing up a great book. Thank you for making me a part of the process. I believe many more .NET developers will finally understand what workflow can do for them thanks to your introduction to the topic. Scott Seely xi

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.