Beginning WF: Windows Workflow in .NET 4.0 (Expert's Voice ... Dedicated to my wife, Donna. Your worth

  • View
    3

  • Download
    1

Embed Size (px)

Text of Beginning WF: Windows Workflow in .NET 4.0 (Expert's Voice ... Dedicated to my wife, Donna. Your...

  • Beginning WF Windows Workflow in .NET 4.0

    n n n

    Mark J. Collins

  • Beginning WF: Windows Workflow in .NET 4.0

    Copyright © 2010 by Mark J. Collins

    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-2485-3

    ISBN-13 (electronic): 978-1-4302-2486-0

    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.

    President and Publisher: Paul Manning Lead Editor: Jonathan Hassell Technical Reviewer: Michael Mayberry Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell,

    Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh

    Project Manager: Debra Kelly Copy Editor: Nancy Sixsmith Compositor: Laureltech Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko

    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 www.springeronline.com.

    For information on translations, please e-mail rights@apress.com, or visit 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 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 www.apress.com.

  • Dedicated to my wife, Donna. Your worth is far above rubies (Prov 31:10). I love you!

  • v

    Contents at a Glance

    Contents.................................................................................................................... vii

    About the Author...................................................................................................... xix

    About the Technical Reviewer .................................................................................. xx

    Acknowledgments ................................................................................................... xxi

    Introduction ............................................................................................................ xxii

    n Part 1: Introduction ................................................................................................1

    n Chapter 1: Building a Simple Workflow..................................................................3

    n Chapter 2: Coded Workflows ................................................................................23

    n Chapter 3: Flowchart Workflow............................................................................33

    n Part 2: Designing Workflows ................................................................................43

    n Chapter 4: Passing Arguments .............................................................................45

    n Chapter 5: Replicated Activities ...........................................................................59

    n Chapter 6: Exception Handling .............................................................................69

    n Chapter 7: Extending the Built-In Activities .........................................................79

    n Part 3: Communication .........................................................................................93

    n Chapter 8: Send and Receive ................................................................................95

    n Chapter 9: Communicating with the Host Application........................................123

    n Chapter 10: Web Services...................................................................................151

  • n CONTENTS AT A GLANCE

    vi

    n Part 4: Workflow Extensions ..............................................................................175

    n Chapter 11: SQL Persistence ..............................................................................177

    n Chapter 12: Custom Extensions..........................................................................209

    n Chapter 13: Tracking ..........................................................................................229

    n Chapter 14: Transactions....................................................................................255

    n Chapter 15: Transactions with Persistence........................................................277

    n Chapter 16: WorkflowServiceHost ......................................................................289

    n Part 5: Advanced Topics.....................................................................................317

    n Chapter 17: Compensation, Confirmation, and Cancellation ..............................319

    n Chapter 18: Collections.......................................................................................345

    n Chapter 19: Interoperability with Workflow 3.5 .................................................361

    n Chapter 20: Policy ..............................................................................................375

    n Appendix: Sample Workflow Project ..................................................................405

    n Index: .................................................................................................................439

  • vii

    Contents

    About the Author...................................................................................................... xix

    About the Technical Reviewer .................................................................................. xx

    Acknowledgments ................................................................................................... xxi

    Introduction ............................................................................................................ xxii

    n Part 1: Introduction ................................................................................................1

    n Chapter 1: Building a Simple Workflow..................................................................3

    A Simple Workflow ............................................................................................................4

    Exploring the IDE ...................................................................................................................................... 4

    Designing the Workflow ........................................................................................................................... 5

    Reviewing Program.cs.............................................................................................................................. 6

    Running the Application ........................................................................................................................... 7

    Adding Procedural Elements .............................................................................................7

    Using Variables......................................................................................................................................... 8

    If ............................................................................................................................................................. 10

    Assign..................................................................................................................................................... 11

    While....................................................................................................................................................... 12

    Sequence................................................................................................................................................ 13

    Delay....................................................................................................................................................... 13

    More Embellishments............................................................................................................................. 14

    Running the Application ......................................................................................................................... 15

  • n CONTENTS

    viii

    Navigating the Designer ......................................