Apress pro WF windows workflow in dot NET 3 5 jun 2008 ISBN 1430209755 pdf

854 264 0
Apress pro WF windows workflow in dot NET 3 5 jun 2008 ISBN 1430209755 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

 CYAN   MAGENTA  YELLOW   BLACK  PANTONE 123 C Books for professionals by professionals ® The EXPERT’s VOIce ® in NET Companion eBook Available Author of NET 2.0 Interoperability Recipes: A Problem-Solution Approach Pro WF: Windows Workflow in NET 3.5 Dear Reader, Thank you, Bruce Bukovics Companion eBook THE APRESS ROADMAP Beginning C# 2008, Second Edition See last page for details on $10 eBook version Beginning C# 2008 Databases Beginning ASP.NET 3.5 in C# 2008, Second Edition Illustrated C# 2008 Beginning XML with C# 2008 Pro C# 2008 and the NET 3.5 Platform, Fourth Edition Pro ASP.NET 3.5 in C# 2008, Second Edition Pro WF Pro WPF in C# 2008, Second Edition Pro LINQ SOURCE CODE ONLINE www.apress.com ISBN 978-1-4302-0975-1 55299 US $52.99 Windows Workflow Since I began my career a few decades ago, I’ve looked for a better way to develop software I imagined that one day software would be developed visually instead of with a text editor I hoped that we would assemble complete applications from prebuilt components, just as my son assembles his exorbitantly priced plastic blocks Now the future is here with Microsoft’s Windows Workflow Foundation (WF) Why am I so excited about WF? Workflow-enabled applications use a declarative programming model rather than a procedural one, separating what to from when to it And the WF designer is tightly integrated with Visual Studio, bringing workflow within reach of every NET developer In the future, I believe most nontrivial applications will be workflow-enabled, and WF is the de facto standard workflow framework for Windows I wrote this book as a comprehensive tutorial on using WF I start with the WF fundamentals to get you up and running quickly After that, I provide coverage of other WF topics, such as local services, event-driven activities, rules, workflow persistence, tracking, transactions, compensation, dynamic updates, web services, ASP.NET, workflow markup, and hosting the workflow designers I’ve updated the first edition of this book with coverage of the new WF features in NET Framework 3.5, including a new chapter dedicated to workflow services I also added a new chapter that explores the development of composite and long-running custom activities As a working developer, I learn a new skill best through practical, hands-on examples So when I wrote this book, I focused on demonstrating WF concepts instead of just talking about them I truly believe that workflows are the next paradigm shift, and I hope this book helps you to use WF in your own applications Pro WF Pro WF: Windows Workflow in NET 3.0 Pro WF Windows Workflow in NET 3.5 Use Windows Workflow Foundation to develop next-generation, workflow-enabled applications in NET 3.5 Bruce Bukovics Bukovics Shelve in Programming/Microsoft/.NET User level: Intermediate–Advanced 781430 209751 this print for content only—size & color not accurate spine = 1.6052" 856 page count Buckovics_975-1FRONT.fm Page i Wednesday, May 28, 2008 4:59 PM Pro WF Windows Workflow in NET 3.5 ■■■ Bruce Bukovics Buckovics_975-1FRONT.fm Page ii Wednesday, May 28, 2008 4:59 PM Pro WF: Windows Workflow in NET 3.5 Copyright © 2008 by Bruce Bukovics 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-4302-0975-1 ISBN-13 (electronic): 978-1-4302-0976-8 Printed and bound in the United States of America 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: Matthew Moodie Technical Reviewers: Brian Robert Myers, Sylvain Groulx Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Beth Christmas Copy Editor: Kim Wimpsett Associate Production Director: Kari Brooks-Copony Production Editor: Ellie Fountain Compositor: Susan Glinert Proofreader: Patrick Vincent Indexer: Julie Grady Artist: Kinetic Publishing Services, LLC 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 orders-ny@springer-sbm.com, or visit http://www.springeronline.com For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http:// www.apress.com Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales 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 You will need to answer questions pertaining to this book in order to successfully download the code Buckovics_975-1FRONT.fm Page iii Wednesday, May 28, 2008 4:59 PM For Teresa and Brennen Buckovics_975-1FRONT.fm Page iv Wednesday, May 28, 2008 4:59 PM Buckovics_975-1FRONT.fm Page v Wednesday, May 28, 2008 4:59 PM Contents at a Glance About the Author xxi About the Technical Reviewers xxiii Acknowledgments xxv Introduction xxvii ■CHAPTER A Quick Tour of Windows Workflow Foundation ■CHAPTER Foundation Overview 29 ■CHAPTER Activities 65 ■CHAPTER Hosting the Workflow Runtime 129 ■CHAPTER Flow Control 167 ■CHAPTER Local Services 215 ■CHAPTER Event-Driven Activities 237 ■CHAPTER Workflow Persistence 297 ■CHAPTER State Machine Workflows 333 ■CHAPTER 10 Transactions and Compensation 369 ■CHAPTER 11 Workflow Rules 417 ■CHAPTER 12 Exception and Error Handling 457 ■CHAPTER 13 Advanced Custom Activities 483 ■CHAPTER 14 Dynamic Workflow Updates 519 ■CHAPTER 15 Workflow Tracking 549 ■CHAPTER 16 Web Services and ASP.NET 595 ■CHAPTER 17 Workflow Services and WCF Integration 625 ■CHAPTER 18 Workflow Serialization and Markup 693 ■CHAPTER 19 Hosting the Workflow Designers 731 ■INDEX 793 v Buckovics_975-1FRONT.fm Page vi Wednesday, May 28, 2008 4:59 PM Buckovics_975-1FRONT.fm Page vii Wednesday, May 28, 2008 4:59 PM Contents About the Author xxi About the Technical Reviewers xxiii Acknowledgments xxv Introduction xxvii ■CHAPTER A Quick Tour of Windows Workflow Foundation Why Workflow? Workflows Are Different Why Windows Workflow Foundation? Your Development Environment Hello Workflow Creating the Workflow Project Introducing the Workflow Designer Using Workflow Activities Entering Code Hosting the Workflow Runtime 10 Running the Application 12 Passing Parameters 12 Declaring the Properties 13 Passing Values at Runtime 13 Making Decisions 15 Creating a Workflow Library 15 Adding Workflow Properties 16 Adding IfElse Activities 16 Adding Calculation Logic 20 Creating the Calculator Client 22 Testing and Debugging the Calculator 26 Summary 28 vii Buckovics_975-1FRONT.fm Page viii Wednesday, May 28, 2008 4:59 PM viii ■C O N T E N T S ■CHAPTER Foundation Overview 29 Workflow Types 29 Sequential Workflows 29 State Machine Workflows 30 Choosing a Workflow Type 31 Foundation Deliverables 32 Class Libraries and Framework 33 Runtime Engine 34 Runtime Services 34 Design-Time Tools 35 NET 2.0 Runtime 35 Runtime Environment 35 Application Host Process 36 Runtime Engine 37 Registered Core Services 39 Registered Local Services 42 Workflow Instance 44 Design-Time Environment 46 Workflow Authoring Modes 46 Project Templates 48 Workflow Designer 48 Activity Designer 54 Rule Condition Editor 55 RuleSet Editor 58 Workflow Debugger 61 Command-Line Workflow Compiler 62 Command-Line Communication Activity Generator 62 Summary 63 ■CHAPTER Activities 65 Understanding Activities 65 A Dual Audience for Activities 66 Class Hierarchy 66 Exploring Standard Activities 67 Custom Workflow Logic 68 Flow Control 68 State Management 70 Event Handling 71 Local Service Communication 72 Buckovics_975-1INDEX.fm Page 806 Thursday, May 29, 2008 2:11 PM 806 ■I N D E X NET 3.0, 3.5, exception handling in, 457 remoting, 626 selecting version of, Operation property, 16 OperationContract attribute, 626–627, 629, 653 OperationInfo class, 652 OperationParameterInfo class, 652 OperationValidation event, 630 OperationValidationEventArgs, 630 transaction support in, 370 WF support in, NetTcpBinding, 633 NetTcpContextBinding, 633 new keyword, 418, 420, 422 NewFunctionActivity, 529, 537 NewWorkflowForm class, 735, 785–787 NewWorkflowName property, 737, 786 NewWorkflowType property, 737, 772 no-code authoring mode, 47, 693, 696–698, 731 converting to code-only, 715–719 operator overloading, 418, 423 operator precedence (,), 421 operators Boolean, 45, 55, 168, 172 rule condition, 420–421 order entry with custom activities, 108 with custom logic, 86–90 implementing, 101–104 outerActivity parameter, 321 _outputParameters variable, 140 using rules with, 712–715 workflow designers for, 731, 734 workflow development, 705–712 defining workflow markup, 707–708 implementing base workflow class, 706 implementing custom activity, 706–707 testing workflow, 710–712 WorkflowRuntimeManager enhancement, 709–710 None option, 423 NonSerializedAttribute, 222 non-workflow objects, 215 NUnit, 111, 114 output parameters, multiple workflows and, 137 OutputParameters collection, 135 output properties, 135 overloaded operators, 420 OwnerActivityName property, 631 ■O object instances, creating, 418–422 OnActivityExecutionContextLoad method, 221, 230 OnClick events, 748 OnEvent method, 279–280, 286, 492, 494, 503, 514 one-way message exchange patterns, 627–629 OnFormClosing method, 26 OnGuessReceived method, 244 OnInitialized event handler, 245–246 OnLoad method, 252, 293, 309, 354 OnMenuClicked method, 748 OnSendMessage method, 341, 343, 352 Open method, 631, 648 ■P parallel execution, 75–76, 194 Parallel ExecutionType, 200–204 ParallelActivity, 69, 77, 167, 669, 680, 682 adding DelayActivity, 192–194 cancellation logic with, 478–481 correlation attributes with, 259–267 event routing with, 258 execution sequence, 191–192 using, 186–193 with WhileActivity, 187–189 ParallelActivityDesigner class, 124 ParameterBindings collection, 72 parameters See also specific parameters binding, 233–234, 599–600 declaring properties, 13 defining as properties of workflow class, 90 defining workflow, 79–83, 104–105 names, 15 output, 135, 137 passing, 12–15 setting for method call, 233–234 Buckovics_975-1INDEX.fm Page 807 Thursday, May 29, 2008 2:11 PM ■I N D E X parentEventHandler parameter, 285 partial classes, 26 partial keyword, 694–695 PartitionCompletedWorkflowInstances stored procedure, 583 partitioning of tracking data, 557 SQL tracking database, 582–583 PartitionOnCompletion property, 557, 582–583 per-call instancing, 632 PerformFlush method, 736, 744, 775 problem solving domain-specific model for, workflows for, 1–2 ProcessGuessActivity, 281–288 Product class, 672 product validation PerformLoad method, 736–741 persistence/persistence services, 40–41, 75, 152, 222, 297 See also SqlWorkflowPersistenceService adding, 152 adjusting permissions, for IIS, 643 custom abstract methods and, 319–322 implementation of, 319–330 testing, 329–330 host application implementation, 305–316 implementing own, 298 programming model, workflow, project templates, 35, 46–48 projects, publishing web service, 597–598 properties adding to project, 16 assigning of one activity, to another, 80 attached, 500 autoimplemented, 13 binding, 106–108, 231 declaring, 13 defining activity, 95–97 dependency, 80–83 importance of, 34, 297 loading and running, 149, 299, 597 local service implementation, 301–302 overview, 297–300 preparing database for, 301 reasons for, 297–298 SqlWorkflowPersistenceService, 300–319 state machine workflows and, 358 testing, 152–155, 316–319 with TransactionScopeActivity, 371 workflow, 3, 303–305, 642 PersistenceDemoService class, 310 PersistOnCloseAttribute, 299, 371 PolicyActivity, 38, 45, 55, 58, 73, 77, 417–418, 427–438 PopulateListWithReferences method, 784 PopulateWorkflowList method, 786 PossibleStateTransitions property, 366 PrepareProWorkflowDatabase.cmd file, 375, 387 Priority property, 420, 499–507 Priority SequenceActivity, 499–507 with custom logic, 85 implementing, 99–101 Program class, 91–92, 135–137 Program.cs file, 10–14, 90–91, 645–646, 678–679, 687 property bindings, 599–600, 615 property types, 80–83 PropertyClass property, 73 PropertyDescriptor class, 753 PropertyGrid control, 775 ProWorkflow database, 372–375 proxy classes, 73 ProxyClass property, 612 ■Q QueryTrackingData method, 561 QueryWorkflowList method, 566 QueueEventArgs, 279 queues See workflow queues ■R ReadCommitted isolation level, 371 ReadUncommitted isolation level, 371 _reasonSuspended variable, 140 RebuildPartitionViews stored procedure, 583 807 Buckovics_975-1INDEX.fm Page 808 Thursday, May 29, 2008 2:11 PM 808 ■I N D E X ReceiveActivity, 71, 74, 77, 238, 629 CanCreateInstance property, 633, 662 CodeActivity as child of, 636 Context property, 670 with SendActivity, 668–692 ServiceOperationInfo property, 630 RetrieveProfile method, 576 ReturnContext property, 675, 677 ReturnProduct method, 672, 683 ReturnValue parameter, 599 Rollback method, 370 rolling back work, 369 using, 629–630, 668–692 workflow-first authoring mode and, 650–652 recursive execution, 213 recursive states, 335–338, 360–362 ReevaluationBehavior property, 425 refactoring, duplicate implementation, 360–361 ReferencesAssemblies property, 722 reflection, 536 RefreshData method, 313 RegisterAttached method, 500 registered core services, 39–42 RootComponent, 775 rule attributes identifying dependencies with, 425–427 indirect relationships between, 446–447 Rule class, 168, 417–422 Condition property, 419 ElseActions property, 420 Name property, 420 Priority property, 420 Reevaluation property, 425 ThenActions property, 420 registered local services, 42–44 RegisterForStatusChange, 491 relational databases, transactions and, 369 Remove method, 521 RemoveFromDesigner method, 743 RemovePropertyValueUIHandler method, 759 RepeatableRead isolation level, 371 ReplaceRuleDefinition method, 547–548 ReplicatorActivity, 69, 77, 167, 194–206 AllChildrenComplete property, 206 behavior of, 194 CurrentIndex property, 197 Rule Condition Editor, 18–19, 55–58, 85, 176 rule conditions, 17, 19, 55–58, 167–168 adding, 108, 176–178 vs code conditions, 45–46 declaring, 420, 421 with IfElseActivity, 176–179 operators, 177–178, 420–421 setting, 107 updating, 538–544 with WhileActivity, 181 rule definitions, replacing, 544–548 Rule editor, 46 events, 205–206 ExecutionType property, 194 InitialChildData property, 194 interrupting execution of, 206 with Parallel workflow, 200–204 with Sequence workflow, 195–199 ReplicatorChildEventArgs, 203 ReplicatorParallelWorkflow, 204 request/response message exchange pattern, 627–629 resource consumption, persistence and, 298 Result property, 24, 137, 167 _result variable, 134 Resume method, 70, 214, 521, 528 RetrieveExistingWorkflows method, 316, 329–330 rule modeling, 45 Rule Set editor, 419 rule sets, 417–418 RuleAction class, 421 RuleActionTrackingEvent objects, 565, 572 rule-based applications, advantages of, 419 RuleChainingBehavior enum, 423–424 RuleCondition class, 168, 419 RuleConditionReference class, 167 RuleDefinitions class, 449, 542–548 RuleExecution object, 450 RuleExpressionCondition class, 419, 452, 542 RuleHaltAction, 421 RuleInvokeAttribute, 425–426, 446–447 RuleReadAttribute, 425–426, 446–447 RuleReevaluationbehavior enum, 425 Buckovics_975-1INDEX.fm Page 809 Thursday, May 29, 2008 2:11 PM ■I N D E X rules, 45–46 actions, 418–422 compiling workflows with, 722–725 composition of, 418 conditions See rule conditions defining, 417–422 runtime engine/environment, 34–46 adding core services to, 148–155 application host process, 36–37 configuring with App.Config, 155–158 core services, 39–42, 148–155 creating multiple instances of, 37 with PolicyActivity, 427–438 to prevent dynamic updates, 522 evaluation of, 418–420 executing in code, 417 forward chaining, 45, 73, 418 if-then-else construct, 418 NET 3.5 enhancements for, 418 with no-code workflows, 712–715 priority of, 418–420, 441–444 reasons to use, 419 reevaluation of, 418 execution scheduling and, 489–490 hosting, 10–12 host applications and, 37 instance events, 38–39 loading and running, 149 registered local services, 42–44 responsibilities of, 38 rules evaluation engine of, 38, 45–46 starting, 135 for state machine workflows, 365–368 thread management in, 162–165 suppressing reevaluation of, 425 tracing, 417, 439–441 tracking, 569–572 understanding, 417–419 using methods within, 444–447 in WF, 419–427 rules activities See specific activities rules editor, 417 rules evaluation engine, 38, 45–46, 168, 417 rules file, 418, 450, 538, 544–546 Rules property, 423 RuleSet Editor, 46, 58, 60 RuleSetReference property, 428 RuleSets, 38, 45, 55, 168, 417 ChainingBehavior property, 423–424 constructing in code, 450–454 creating new, 429–430 defining, 423–425 defining workflow logic with, 78 executing in code, 447–450 rules within, 73 using methods in, 445 RuleStatementAction class, 421 RuleUpdateAction, 421–424 RuleValidation object, 449–450 RuleWriteAttribute, 425–426, 446–447 Run method, 150, 153, 727 RunForever method, 480 visibility, 549 workflow instances, 44–46 runtime parameters, 13–15 runtime thread management, 35 RunWorkflow method, 92, 136–137, 164 ■S Save method, 320–321 SaveCompletedContextActivity method, 320–321, 324 SaveWorkflow method, 775, 781 SaveWorkflowDefinition method, 780–781 SaveWorkflowInstanceState method, 319–323 scalability, persistence and, 298 scheduler services, 40–41, 162–165 Select Condition dialog, 18 SelectedWorkflowType property, 786 SelectionChanged event, 775 selectionService_SelectionChanged method, 775 self-hosting WCF services, 628 workflow services, 631–632, 646–650 SelfUpdatingWorkflow (example) host application implementation, 536–537 implementing, 533–536 testing workflow, 537–538 SellItemSerializedWorkflow, 447–454 Send method, 585 809 Buckovics_975-1INDEX.fm Page 810 Thursday, May 29, 2008 2:11 PM 810 ■I N D E X SendActivity, 74, 77, 625, 629 accessing WCF services with, 662 ChannelToken property, 630 Context property, 675–677 with ReceiveActivity, 668–692 using, 630–631, 662–668 sender argument, 197 SendHintActivity implementing, 288–290 modifying host application, 292–295 modifying workflow, 291–292 testing workflow, 295 SendMessage method, 241–246 Sequence ExecutionType, 195–199 SequenceActivity, 66, 69, 77, 95, 180, 375, 669, 682 compared with EventDrivenActivity, 238 as default base class for custom composite activity, 484 execution pattern, 484 implementing, 492–496 instances, 458 with ParallelActivity, 186 priority, 499–507 with WhileActivity, 182–183 SequenceActivityDesigner, 492 SequenceTest class, 498 Sequential Workflow Console Application, 48 sequential workflow designer view, 49–50 Sequential Workflow Library, 48 sequential workflows, 3–4 beginning and end points for, choosing, 31–32 client workflow implementation, 680–687 declaring fault handlers for, 458 inventory workflow implementation, 672–677 order of activities in, overview, 29–30 vs state machine workflows, 333–335 SequentialActivityDesigner class, 124–126 SequentialWorkflowActivity class, 10, 32, 66 Serializable attribute, 672 Serializable isolation level, 371 serialization deserialization, 726–730 of events passed, 244 to markup, 715–719, 727, 729, 744 WorkflowmarkupSerializer class, 449, 715–719, 740–741, 744 serialization constructors, 121 Serialize method, 324–326, 715–719, 729 SerializeToMarkup method, 716–718, 727, 729, 744 SerializeToolboxItem method, 763 service contracts, 625 as stateless operations, 632 defining, 626–627, 634–635, 653–654 defining, for multiple workflows, 670–672 multiple service operations in, 629 namespaces for, 635 renaming, 652 transport mechanisms and, 626 service endpoints, 630 service faults, returning exceptions as, 670, 683 service host configuring, for self-hosting workflow services, 648–649 developing, for self-hosting workflow services, 646–648 testing, 650 service implementation class, 217 service interface, defining, 241–242 ServiceBehavior attribute, 627 ServiceContract attribute, 626, 629, 635, 653 ServicedComponent class, 370 ServiceHost class, 628, 631 ServiceModel Metadata Utility, 628 ServiceOperationInfo property, 630, 635, 650, 675, 683 services See also workflow services, specific services adding, 41, 148–155 core, 39–42, 129, 148–155, 162–165, 215 defined, 34 identifying methods as, 626 implementing own, 41 local See local services multiple operations, 629 runtime, 33–42, 149 workflow designer, 733–734 Buckovics_975-1INDEX.fm Page 811 Thursday, May 29, 2008 2:11 PM ■I N D E X Set method, 500 SetPartitionInterval strored procedure, 582 SetPriority method, 504 SetStateActivity, 70–71, 77, 336, 347–348 SetValue method, 81, 756 SharedConnectionWorkflowCommitBatchService, 558 SharedConnectionWorkflowCommitWorkBatchService class, 42, 372 SharedWorkflows assembly, 788 ShowCode methods, 753 ShowContextMenu method, 746 simple activities, 45, 65 Site property, 775 software requirements, Solution Explorer window, 5–6 SplitContainer control, 770 SQL Server managing transactions in, 370 persistence server features, 319 standard persistence service, 298–299 sqlcmd command-line tool, 152–153, 372, 375 SQL Server Express, 152, 372–375 SQL Server Management Studio Express, 372 SQL tracking database See SqlTrackingService sqlcmd command-line tool, 152–153, 372, 375 SqlConnection class, 370, 378 SqlTrackingQuery class, 552, 560, 566, 583 SqlTrackingService, 42, 372, 549, 552, 584 configuring, with App.config file, 559 custom tracking profiles, 552 maintaining, 582–583 partitioning, 557, 582–583 preparing, for tracking service, 553–554 PartitionOnCompletion property, 557, 582–583 tracking data event types, 550–551 using, 553–567 developing host application, 556–558 developing test workflow, 554–556 executing host application, 558 preparing database, 553–554 retrieving tracking data, 559–567 with SqlWorkflowPersistenceService, 558 working with tracking profiles, 573–574 SqlTrackingWorkflowInstance, 572 SqlTransaction class, 370 SqlWorkflowPersistenceService, 42, 298, 300, 372, 597, 601, 642 adding, 151–152 features, 319 SqlTrackingService with, 558 testing, 152–155 using, 300–319 host application implementation, 305–316 local service implementation, 301–302 preparing database, 301 testing application, 316–319 workflow implementation, 303–305 SqlWorkflowPersistenceService class, 34 standard activities, 45, 67–78 custom workflow logic, 68 event handling, 71–72 exceptions and error handling, 76 flow control, 68–70 local service communication, 72 rules, 73 state management, 70–71 summary of, 77–78 transactions, compensation, and synchronization, 74–76 web services, 73–74 workflow services, 74 Start method, 136, 521 Started method, 269–270 StartedState, 654 StartRuntime method, 41, 135, 150, 155 StartWorkflow method, 142, 150, 662 state machine classes, 335–336 EvenDrivenActivity, 336–337 SetStateActivity class, 336 StateActivity class, 335–337 StateMachineWorkflowActivity class, 335–337 state machine designer view, 51 State Machine Workflow Console Application, 48 State Machine Workflow Library, 48 state machine workflows, accessing runtime information, 365–368 choosing, 31–32 eliminating duplicate event handlers from, 360–362 811 Buckovics_975-1INDEX.fm Page 812 Thursday, May 29, 2008 2:11 PM 812 ■I N D E X example, 334 fault handlers and, 458 identifying available events, 362–365 implementation, 338–360 defining events, 349–351 defining first event, 346–348 StateInitializationActivity, 71, 78, 348–349, 458 StateInitializationActivity class, 336 stateless workflow services developing, 634–640 configuring, 637–639 defining service contract, 634–635 defining local service interface, 339–341 defining states, 345 designing state machine, 338–339 designing user interface, 352–353 of host application, 352–358 of local service, 341–343 testing, 358–362 of workflow, 344–351 initial and completed states in, 337 overview, 30, 333–337 persistence for, 298, 358 implementing workflow, 635–637 stateless services and, 633 testing, 637–640 StateMachineWorkflowActivity class, 32, 66, 335–337 reasons to use, 334–335 recursive composition of states in, 335–337 vs sequential workflows, 333, 335 state management activities, 70–71 state management activities, 70–71 state transitions, 335 to leaf states, 361 raising external events and, 357 using SetStateActivity, 337 StateActivity class, 66, 70, 77, 335–337, 458 StateFinalizationActivity class, 71, 78, 336, 458 stateful web services, 607–612 defining interface, 608 implementing, 608–611 publishing, 612 testing, 612 stateful workflow services, 652–668 developing, 652–662 client application, 659–662 defining service contract, 653–654 hosting in IIS, 658–659 implementing workflow, 654–658 testing, 662 using SendActivity, 662–668 developing client application, 666–668 implementing workflow, 662–666 testing, 668 workflow services and, 625, 633 StateMachineWorkflowInstance class, 365–368 states completed, 337 defined by state machine workflows, 333 dynamic updates, 520–521 identification of, 335 identifying events within, 335 initial, 337 leaf, 337, 361 multiple, with duplicate event handlers, 338 recursive composition of, 335–337, 360–362 saving of, 299, 319–320, 326 transitions between, 70, 333, 335, 337, 357, 361 States property, 366 StopReceived event, 314, 317–319 StopWaiting method, 140 StopWorkflow method, 654 stored procedures See also specific types for partitioning, 582–583 tracking profiles, 573 structural changes, dynamic updates for, 519–520 Subscribe method, 279–280, 283–285 SubscribeToEvents method, 141 subtraction operator (–), 421 Suspend method, 159–162 SuspendActivity, 70, 78, 214, 521–522, 526, 541 svc file, creating, 641 svcutil.exe utility, 628 SynchronizationHandles property, 76 SynchronizationScopeActivity, 75–78 system interactions, modeling, System.ComponentModel.Design, 732 Buckovics_975-1INDEX.fm Page 813 Thursday, May 29, 2008 2:11 PM ■I N D E X System.ComponentModel.Design.DesignSurface class, 732–733 System.Configuration assembly, 227 System.Drawing.Design, 732 System.ServiceModel namespace, 34, 631 System.Transactions namespace, 370 System.Workflow namespaces, 33–34 System.Workflow.Activities namespace, 5, 32–33, 629 System.Workflow.Activities.Rules namespace, 33, 419 System.Workflow.ComponentModel namespace, 5, 33 System.Workflow.ComponentModel.Activity class, System.Workflow.ComponentModel.Compiler namespace, 33, 732 System.Workflow.ComponentModel.Design namespace, 33, 732 System.Workflow.ComponentModel.Design WorkflowDesignerLoader class, 732–733 System.Workflow.ComponentModel.Design WorkflowView class, 732–733 System.Workflow.ComponentModel Serialization namespace, 33 System.Workflow.Runtime namespace, 5, 33 System.Workflow.Runtime.Configuration namespace, 33 System.Workflow.Runtime.Debug Engine namespace, 33 System.Workflow.Runtime.Hosting namespace, 34 System.Workflow.Runtime.Tracking namespace, 34 System.WorkflowServices namespace, 6, 629 system-provided bindings, 628, 633 ■T TargetActivityName property, 389 TargetStateName property, 70, 348 TargetWorkflow property, 70, 213 templates, project, 35 Terminate method, 159–161 TerminateActivity, 70, 78, 213 test fixtures, 112 TestValue dependency property, 486 themes, custom, 124–125 ThenActions property, 73, 418–421 this keyword, 85, 176, 244, 431 thread affinity, 254 thread management, 35, 162–165 thread synchronization, 11 ThreadPoolWorkCallback method, 511 throw statement, 76 ThrowActivity, 76–78, 471–473 time delays, adding, with DelayActivity, 192, 194 TimeoutDuration property, 371 ToolboxBitmap attribute, 122 ToolboxItem class, 763 ToolboxItemAttribute, 122, 767–769 ToolboxItemType property, 768 trace logs, 417, 443 tracing rules, 439–441 TrackData method, 551, 568–569 tracking See also tracking profiles benefits of, 552–553 developing tracking service, 584–592 introduction, 549 maintaining SQL tracking database, 582–583 rules evaluation, 569–572 tracking event types, 550–551 understanding, 549–553 user track points, 568–569 using SqlTrackingService, 553–567 tracking channel, implementing, 584–586 tracking data in central repository, 553 data access, 583 event types, 550–551 extracting, with custom tracking profiles, 572–582 flexibility of, 553 partitioning, 557 retrieving, 559–567, 572 using, 552 tracking events, 562 tracking profiles creating, 578–581 custom, 551–552 extracting data with, 572–582 flexibility of, 552 implementing, 574–578 stored procedures, 573 tables and views associated with, 573 813 Buckovics_975-1INDEX.fm Page 814 Thursday, May 29, 2008 2:11 PM 814 ■I N D E X testing, 581–582 version numbers, 573, 590 working with, 573–574 Tracking service class, 42 tracking services, 40–42, 550 See also SqlTrackingService developing, 584–592 implementing custom, 586–590 implementing tracking channel, 584–586 testing custom, 590–592 TrackingChannel class, 584 TrackingConsoleWriter class, 560–567, 572 TrackingProfile objects, 574–577 TrackingProfileHelper class, 574–578, 580–581 TrackingProfileSerializer class, 576–577 TrackingRecord class, 562 TrackingRulesWorkflow implenting, 570 testing, 571–572 TrackingService class, 584–590 TrackingWorkflowEvent values, 550–551 Transaction class, 370 TransactionAttribute, 370 TransactionOptions property, 371 transactions, 369 enlisting work in, without resource manager, 409–412 implicitly managed, 370 maintaining consistency with, 387 in relational databases, 369 support for, in NET, 370 support for, in WF, 370–372 understanding, 369–372 TransactionScope class, 370 TransactionScopeActivity, 75, 78, 369–372 adding to compensatable activities, 404–405 persistence service and, 299, 371, 413 testing workflow, 382–387 using, 372–387 TransientWorkflow property, 521, 529, 542 transport mechanisms, services contracts and, 626 transport protocol, 628 try/catch blocks, 52, 457 TryGetWorkflow method, 561 TryReloadProfile method, 588 TryUnload method, 299 turns-based execution, 167 Type (workflow), 222, 551–552, 721 type selector dialog, 465 TypeConverter, 757 TypePersistenceException, 320 TypeProvider class, 728, 737, 767, 772, 778, 781, 784 ■U UI thread, 312 UIcontrols, updating, 312 unhandled exceptions, 458 compensation logic and, 473 default behavior with, 460–464 Uniform Resource Identifier (URI), 627 Uninitialize method, 284 unit testing, custom activities, 111–114 Unload method, 299 UnloadOnIdle method, 152, 155, 299–300, 322, 325 UnlockWorkflowInstanceState method, 321 Unsubscribe method, 279–280, 285 UntilCondition property, 70, 206–207 Update statements, 418, 422, 424 UpdateCompletedWorkflow method, 312–313 UpdateDefaultTrackingProfile, 574 UpdateDisplay method, 312 UpdateOnly option, 423 UpdateProfile method, 577, 580–581 UpdateTrackingProfile stored procedure, 574, 577 UseActiveTimers property, 163, 597 user interface designing, for host application, 352–353 threads, 312 updating controls, 254 user track points, creating, 568–569 user tracking events, 551 UserControl class, 775, 760 UserTrackingLocation class, 551, 590 UserTrackingRecord class, 564–565, 572 UserTrackPoint class, 551, 590 UserTrackPoints class, 574 UseWorkflowWebsite, 619–623 using code block, 11 using statement, 136–137, 150, 661 Buckovics_975-1INDEX.fm Page 815 Thursday, May 29, 2008 2:11 PM ■I N D E X ■V Validate method, 117–118, 521, 532 ValidateAccountActivity, 106–107 ValidateAccountTest method, 113 ValidateAndApplyChanges method, 529, 543 ValidateProductActivity, 107–108 validation class, implementation of, 115–118 validation errors, testing for, 118–119 validation, activity, 114–119 ValidationError objects, 521 ValidationError.GetNotSetValidationError method, 119 ValidationErrorCollection, 118 Validator class, 115–118 validators, assigning to activities, 118 values, passing, at runtime, 13–15 variables instance, 82, 140 serialization of, 222 Verbs property, 746 View CompensatableSequence, 474 View Fault Handlers option, 464 Virtual Directory Creation Wizard, 641 visibility, 549, 553 visual controls, for forms, 306 Visual Studio debugging in, 464 design tools for, 35 images included with, 122 no-code workflows and, 734 project templates, 35, 46–48 WF included with, Visual Studio 2005, 3, 122 Visual Studio 2008, built-in WF support for, new features of, Visual Studio Toolbox, custom activties and, 105–106 customizing, 114, 120–123 workflow designer and, 49–50 visual workflow tools, 46 activity designer, 54–55 command-line workflow compiler, 62 project templates, 48 Rule Condition Editor, 55–58 RuleSet Editor, 58–60 workflow debugger, 61–62 workflow designer, 48–54 ■W WaitAll method, 144, 151 WaitForIdle property, 357 WaitHandle property, 144, 147, 163 _waitHandle variable, 134–136 WaitingForStartupState, 654 wca.exe utility, 62, 237, 256–257 WCF See Windows Communication Foundation wcf.exe, 47 WcfSvcHost.exe, 637 WcfTestClient.exe, 637 web service workflows defining interface, 598 defining workflow, 598–600 development of, 598–604 publishing workflow, 601 stateful, 607–612 testing, 602–604 web services activities, 73–74, 595–599 debugging, 602 default namespace, 604 fault return, 605–607 invoking from workflow, 612–617 publishing workflows as, 595–598, 601–602 testing, 602–604, 607 WF support for, 595, 629 web sites, testing, 623 Web.config file, 601 configuring, 641–642 modifying, 619–620 for publishing as web service, 597, 601–602 WebService directive, 601 WebServiceFaultActivity, 74, 78, 596–597, 605, 607 WebServiceInputActivity, 71, 73, 238, 595–600, 609–610 WebServiceOutputActivity, 73–74, 78, 595–600 WF See Windows Workflow Foundation wf extension, 326 wfc extension, 326 815 Buckovics_975-1INDEX.fm Page 816 Thursday, May 29, 2008 2:11 PM 816 ■I N D E X wfc.exe (command-line workflow compiler), 46–47, 62, 693, 698, 725–726 WhenCondition property, 70, 206–208 while statement, 180 WhileActivity, 68–69, 78, 167, 247 adding to workflow, 181–182 Condition property, 168 executing child activities of, 270–271 with ParallelActivity, 187–189 SequenceActivity with, 180–183 using, 180–185 Windows Activation Services (WAS), 34, 628 Windows Communication Foundation (WCF), 34 authoring modes for, 74 bindings, 627–628 endpoints, 627–628 hosting and configuration, 628 integration of workflows with, 625, 628 message exchange patterns supported by, 627 overview, 625–628 service contracts, 626–627 workflow services for, 74 Windows Forms Application, 22 Windows Forms controls, thread affinity, 254 Windows Presentation Foundation (WPF), 82, 626, 695 Windows SDK, 256 Windows Workflow Foundation (WF) activities, architecture, 32 community, components, 32–35 creating workflow in, 4–12 design-time environment, 46–62 design-time tools, 35 development environment, 3–4 framework, 33 hosting workflow runtime, 10–12 minimum requirements for, reasons to use, 2–3 runtime environment, 35–46 transaction support in, 370–372 using rules in, 419–427 workflow designer See workflow designer work batches, 320 workflow activities See activities Workflow Activity Library, 48 workflow authoring modes See authoring modes workflow classes See also specific classes declaring variables and properties for, 13 execution context and, 204 implementing custom, in code-only workflow, 706 libraries, 46 workflow debugger, 27, 35, 46, 61–62 workflow definitions, creating new, 789–792 workflow designer, 6–7, 46–54 adding event handlers with, 54 cancel handler view, 53–54 classes, 732–733 custom, 114 fault handler view, 52 functionality implementation, 732 hosting, 714, 731 namespaces, 732 overview, 731–732 sequential workflow view, 49–50 services, 733–734 setting breakpoints within, 27 state machine view, 51 toolbar, 50 workflow designer application assembly references, 781–784 building, 734–786 AssemblyReferenceForm implementation, 782–784 EventPropertyDescriptor implementation, 753–758 MainForm implementation, 776–782 NewWorkflowForm implementation, 785–787 project creation, 735 WorkflowDesigner implementation, 770–776 WorkflowEventBindingService implementation, 749–753 WorkflowLoader class implementation, 736–744 WorkflowMenuService implementation, 745–748 Buckovics_975-1INDEX.fm Page 817 Thursday, May 29, 2008 2:11 PM ■I N D E X WorkflowPropertyValueService implementation, 758–760 WorkflowToolboxService implementation, 760–, 770 classes for, 735–736 referenced assemblies, 767 using, 787–791 workflow commands, 748 workflow exception handling See exception handling workflow execution, synchronous, 162–165 workflow hosting with App.Config, 155–158 example (simple), 130–137 approach evaluation, 137 host application implementation, 133–137 test workflow implementation, 130–133 implementing workflow instance wrapper, 138–140 overview, 129–130 with workflow manager class, 140–155 workflow instance IDs (Guids), 45, 258, 324–326 event processing and, 239 as local variable, 269 retrieval of, 244 Started method and, 269 retrieval of, 328 rule tracing and, 440 workflow instances, 45–46, 130 controlling, 159–162 creation of, 44 defined, 44 dynamic updates to, 519–520 execution of, 44, 135–137, 483 exposing as WCF services, 34 identification of, 44–45 idle, 42 local services and, 42–43 running multiple, 137 tracking data from, 552 wrapper implementation, 138–140 _workflowInstance variable, 140 workflow library, creating, 15–16 workflow manager classes, 174, 223 hosting with, 148–155 implementing, 140–148 workflow markup See markup; XAML workflow models, 508, 693 See also authoring modes workflow namespaces, 33–34 workflow parameters See parameters workflow persistence See persistence/persistence services workflow programming model, workflow projects assembly references, 5–6 calculator application example, 16–28 creating, 4–6, 94–98 with custom activities, 94–98 entering code in, 8–10 running, 12 workflow properties See properties workflow queues, 278–279, 284, 362 workflow rules See rules workflow runtime See runtime engine/ environment workflow runtime audience, 94 _workflowRuntime variable, 134, 141 workflow services activities, 74 authoring styles supported by, 629–630 configuration, 631–632, 637–640 context, 670–692 context management, 632–634 conversations, 668–692 debugging, 26–28, 35, 61–62 deployment, 643 developing client application, 643–646 hosting, 631–632, 640–646 implementing workflow, 635–637 instancing, 632–634 introduction to, 625 loading and running, 149 overview, 628–634 persistence service testing, 152–155 self-hosting, 646–650 serialization of, 222 stateful See stateful workflow services stateful services and, 625, 633 stateless See stateless workflow services stateless services and, 633 testing, 637–640 using SendActivity, 662–663, 666–668 817 Buckovics_975-1INDEX.fm Page 818 Thursday, May 29, 2008 2:11 PM 818 ■I N D E X workflow states See states workflow status implementing class for, 305–306 tracking event and, 550–551 _workflows variable, 141 workflow thread, 312 workflow tracking See tracking workflow updates See dynamic updates Workflow.xoml.cs file, 47 Workflow1 class, 10 Workflow1.cs file, 16, 20 Workflow1.designer.cs file, 47 Workflow1.xoml.cs, 47 WorkflowAborted event handler, 147 WorkflowChanges class, 521–522 WorkflowChanges instance, 529, 536, 542 WorkflowChanges object TransientWorkflow property, 521, 529 Validate method, 521, 532 WorkflowCommitWorkBatchService, 371 WorkflowCompiler class, 693, 722 WorkflowCompilerParameters class, 722, 723, 725 WorkflowCompleted event, 11, 92, 135–136, 313 WorkflowCompleted event handler, 24–25, 147 WorkflowCompletedEventArgs, 135 WorkflowCreated event, 521–542 WorkflowDataTrackingExtract objects, 580 WorkflowDesigner class, 735, 760 See also workflow designer CreateNewWorkflow method, 782 implementation, 770–776 LoadWorkflow method, 779–780 SaveWorkflow method, 781 visual design, 771 WorkflowDesignerLoader class, 736–737 WorkflowEnvironment.BatchWork property, 409 WorkflowEnvironment.WorkflowInstanceId method, 323 WorkflowEventBindingService class, 736, 749–753 WorkflowEventTypeConverter class, 757 workflow-first authoring mode, 74, 625, 629 workflow-first services, 650–652 WorkflowIdled event, 363–364, 521 WorkflowInstance class, 12, 33, 38, 44, 129, 159–162, 279 GetWorkflowQueueData method, 362–364 implementing wrappers for, 138–140 instances of, 136 Suspend method, 159–162 Terminate method, 159–161 WorkflowInstanceWrapper class, 144, 147, 463 WorkflowLoader class, 735 custom services for, 738 implementation, 736–744 PerformFlush method, 744 PerformLoad method, 739 WorkflowMarkupSerializer class, 449, 715–719, 740–741, 744 Deserialize method, 726–730 Serialize method, 729 WorkflowMenuCommands class, 748 WorkflowMenuService class, 735, 745–748 WorkflowPersistence database, 642–643 WorkflowPersistenceService class, 298, 319–323 WorkflowPropertyValueService class, 736, 758–760 WorkflowQueue class, 278 WorkflowQueueInfo objects, 279, 362–364 WorkflowQueuingService, 278, 284, 288 WorkflowRuntime class, 11, 34, 36, 134, 631 application host process, 37 GetWorkflow method, 45 instance events, 38–39 loading local services and, 226–27 runtime engine, 37–39 WorkflowTerminated event, 458–460 WorkflowRuntime event, 521 WorkflowRuntime event handlers, 141, 146–147 WorkflowRuntime instances, 44, 135, 141 WorkflowRuntime property, 688 WorkflowRuntimeBehavior object, 632, 688 WorkflowRuntimeClass, 214 WorkflowRuntimeManager class, 141–148, 175, 463 AddServices method, 152 enhancing, for code-only workflow, 709–710 external construction of, 150 StartWorkflow method, 150 WaitAll method, 151 Buckovics_975-1INDEX.fm Page 819 Thursday, May 29, 2008 2:11 PM ■I N D E X WorkflowRuntimeService class, 33, 511 workflows activities See activities activity execution context, 320–321 adding branches to, 170 adding code conditions to, 171–172 adding custom logic to See custom logic adding event handlers to, 54 adding IfElseActivity to, 170–171 adding logic to, 65, 68 adding WhileActivity, 181–182 adding workflow property to, 169–170 choosing type of, 31–32, 334 code-only See code-only authoring mode code-separation, development, 703–705 creating, 4–12 decision making with, 15–28 defined, 1–2 defining event handlers for, 271–275 defining mainline of execution for, 270–271 defining, with custom activities, 105–110 dynamic updates to, 531–538 event routing in, 258–259 execution environment for, 37–39 execution of, 12, 44, 136 exposing as WCF services, 36 flow control in See flow control hosting, 36–37 idle, 299, 521 implementing, 220–223245–250, 262–265, 270–275 interaction between local services and, 215–216 invoking web service from, 612–617 with manual event correlation, 258–267 modifying, 257, 291–292 monitoring status of, 11 with multiple conversations, 669 no-code See no-code authoring mode passing parameters to, 12–15 persistence of See persistence publishing as a web service, 595–602 purpose of, 1–2 recursive execution of, 213 restarting, 70 with rules See rules running multiple, 151, 155 running, with custom activties, 110–111 saving state of, 299–300 sequential See sequential workflows state machine See state machine workflows states See states structure, 519 suspending, 214, 521–522 terminating, 213 testing, 174–179, 184–185, 616–617 CAGWorkflow, 211–212 correlation attributes, 265–267 EventHandlingScopeActivity example, 275–278 for HandleExternalEventActivity example, 255–256 with local services, 223, 225, 231–235 parallel, 190–191, 204 SendHintActivity, 295 sequence, 198–199 unloading idle, 300, 322, 325 using from ASP.NET, 618–624 web service See web service workflows WorkflowServiceHost class, 34, 631–632, 648, 688 WorkflowSuspended event, 214, 521, 526–528 WorkflowSuspended event handler, 147 WorkflowSuspendedEventArgs, 214 WorkflowTerminated event, 11, 92, 136, 252, 458, 460 WorkflowTerminated event handler, 147 WorkflowToolboxService class, 736, 760–763, 767–770 workflow-to-workflow conversations, 669 WorkflowTrace.log file, 439, 443 WorkflowTrackPoints, 574, 589 WorkflowValidationFailedException, 712, 721 WorkflowView, 775 WorkflowWebHostingModule, 597, 604, 607, 620 WorkRequest class, 509 WorkResponse class, 509 WorlflowLoader class, 745 WPF See Windows Presentation Foundation wrappers, for workflow instances, 138–140 WriteBodyToConsole method, 564, 586 WriteMessageActivity, 789 819 Buckovics_975-1INDEX.fm Page 820 Thursday, May 29, 2008 2:11 PM 820 ■I N D E X WriteRuleData method, 564–565 WriteSingleInstanceToConsole method, 564, 572 WSHttpBinding, 633 WSHttpContextBinding, 633, 639, 653, 659, 668 ■X x:Class attribute, 708, 721 x:Class entry, 705 XAML (Extensible Application Markup Language), 47, 695, 696, 698, 731 xaml files, 695 xmlns entries, 705 XmlSerializer, 627 xoml (markup) files, 46–47, 693–696, 698, 704, 712, 731 ... Buckovics_9 75- 1FRONT.fm Page i Wednesday, May 28, 2008 4 :59 PM Pro WF Windows Workflow in NET 3. 5 ■■■ Bruce Bukovics Buckovics_9 75- 1FRONT.fm Page ii Wednesday, May 28, 2008 4 :59 PM Pro WF: Windows Workflow. .. 33 3 Why a State Machine Workflow? 33 4 State Machine Workflow Overview 33 5 Implementing a State Machine Workflow 33 8... http://www.springeronline.com For information on translations, please contact Apress directly at 2 855 Telegraph Avenue, Suite 600, Berkeley, CA 947 05 Phone 51 0 -54 9 -5 930 , fax 51 0 -54 9 -5 939 , e-mail info @apress. com, or

Ngày đăng: 20/03/2019, 11:28

Từ khóa liên quan

Mục lục

  • Pro WF: Windows Workflow in .NET 3.5

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewers

  • Acknowledgments

  • Introduction

    • Who Should Read This Book

    • An Overview of This Book

      • Chapter 1: A Quick Tour of Windows Workflow Foundation

      • Chapter 2: Foundation Overview

      • Chapter 3: Activities

      • Chapter 4: Hosting the Workflow Runtime

      • Chapter 5: Flow Control

      • Chapter 6: Local Services

      • Chapter 7: Event-Driven Activities

      • Chapter 8: Workflow Persistence

      • Chapter 9: State Machine Workflows

      • Chapter 10: Transactions and Compensation

      • Chapter 11: Workflow Rules

      • Chapter 12: Exception and Error Handling

      • Chapter 13: Advanced Custom Activities

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan