Microsoft Windows Workflow Foundation 4.0 Cookbook - Andrew Zhu - E-Book

Microsoft Windows Workflow Foundation 4.0 Cookbook E-Book

Andrew Zhu

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Windows Workflow Foundation 4.0 (WF) is a significant part of .NET Framework 4.0. WF makes workflow technology available to every single programmer that uses the .NET Framework 4.0. It is easy to create long running and distributed programs using WF with the right knowledge. With this book, you will discover that working with workflows is easy.

This book provides both step-by-step recipes and relevant background information. It covers all the important aspects of Windows Workflow Foundation 4.0. The best thing about this book is that all recipes are based on real-world experiences of Andrew Zhu. Andrew is a global WF and BizTalk technology support engineer for Microsoft. This book covers everything you need to know, when working with workflows. Get to grips with flow control activities, messaging, and transaction processes with easy to understand steps followed by explanations. You will quickly learn to use collection and custom WF activities and WF services.You will see recipes that illustrate integration of Windows Workflow with other applications such as WPF, ASP.NET, WCF service.Lastly, you will discover how easily you can customize W4 Designer with WF rule engine and others.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 191

Veröffentlichungsjahr: 2010

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Microsoft Windows Workflow Foundation 4.0 Cookbook
Credits
About the Author
About the Reviewers
Foreword
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Workflow Program
Introduction
Creating the first WF program: HelloWorkflow
How to do it...
How it works...
There's more...
Creating a WF program using C# Code
How to do it...
How it works...
There's more
Initializing a WF program using InArguments
How to do it...
How it works...
There's more
Creating a WF program using OutArgument
How to do it...
How it works...
There's more...
Creating a WF program using InOutArgument
How to do it…
How it works...
There's more...
See Also
Using Variable in a WF program
How to do it...
How it works...
There's more...
See Also
Running a WF program asynchronously
How to do it...
How it works...
Customizing a MyReadLine activity with Bookmark
How to do it...
How it works...
Converting a WF program instance to XAML
How to do it...
How it works...
Loading up a WF program from an XAML file
How to do it...
How it works...
Testing a WF program with a unit test framework
How to do it...
How it works...
There's more...
Debugging a WF program
How to do it...
There's more...
2. Built-in Flow Control Activities
Introduction
Using the Foreach activity
How to do it...
How it works...
There's more...
A number guessing game in Sequence
How to do it...
How it works...
A number guessing game using a flowchart
How to do it...
How it works...
There's more
Using the InvokeMethod activity
How to do it...
How it works...
There's more
Using the Switch<T> activity in Sequence workflow
How to do it...
How it works...
There's more
Using the FlowSwitch<T> activity
How to do it...
How it works
See Also
Using the Parallel activity
How to do it...
How it works...
Using the ParallelForEach<T> activity
How to do it...
How it works...
Using the Pick activity
How to do it...
How it works...
There's more
Handling errors
How to do it...
How it works...
3. Messaging and Transaction
Introduction
Creating a pure WCF service
How to do it...
How it works...
There's more
Receiving and replying to a WCF message
How to do it...
How it works...
Receiving and replying to a WCF message in code workflow
How to do it...
How it works...
Sending and receiving a reply to a WCF message
Getting ready
How to do it...
How it works...
There's more
Sending and receiving a reply to a WCF message in code workflow
Getting ready
How to do it...
How it works...
Using CancellationScope activity
How to do it...
How it works...
There's more
Performing a transaction by using TransactionScope activity
How to do it...
How it works...
There's more
Performing compensation by using Compensable activity
How to do it...
How it works...
Performing manual compensation by using Compensate activity
How to do it...
How it works...
Performing confirmation by using Confirm activity
How to do it...
How it works...
4. Manipulating Collections
Introduction
Printing collection items
How to do it
How it works...
There's more
Using AddToCollection<T> activity
Getting ready...
How to do it...
How it works...
There's more
Using ClearCollection<T> activity
Getting ready
How to do it...
How it works...
There's more
Using RemoveFromCollection<T> activity
Getting ready
How to do it...
How it works...
There's more
Using ExistsInCollection<T> activity
Getting ready
How to do it...
How it works...
There's more
5. Custom Activities
Introduction
Creating an activity by inheriting the root activity
How to do it...
How it works...
There's more
Creating a FileWriter activity
How to do it...
How it works...
There's more
Creating a SendEmail activity
How to do it...
How it works...
Creating an Input Message activity using Bookmark
How to do it...
How it works...
Creating an Asynchronous HTTP Get activity
How to do it...
How it works...
Creating a Composite activity
How to do it...
How it works...
Creating an Activity Designer for the SendEmail activity
How to do it...
How it works...
Creating an Activity Designer for theMySquence activity
How to do it...
How it works...
6. WF4 Extensions
Introduction
Configuring ETW tracking
Getting ready
How to do it...
How it works...
Creating FileTrackingParticipant
How to do it...
How it works...
Configuring the SQL persistence store
Getting ready
How to do it...
How it works...
Loading a persisted workflow from the database
Getting ready
How to do it...
How it works...
There's more
Using a persistence participant to persist additional data
Getting ready
How to do it...
How it works...
Using a customized extension
How to do it...
How it works...
There's more
7. Hosting Workflow Applications
Introduction
Hosting a workflow service in IIS7
Getting ready
How to do it...
How it works...
There's more
See also
Hosting workflow in ASP.NET
Getting ready
How to do it...
How it works...
There's more
Hosting workflow in WPF
How to do it...
How it works...
Hosting workflow in a Windows Form
How to do it...
How it works...
8. Custom Workflow Designer
Introduction
Implementing designer layout
How to do it...
How it works...
See also
Implementing Toolbox, Workflow Designer, and Property Inspector views
Getting ready
How to do it...
How it works...
Implementing New Workflow and Load Workflow events
Getting ready
How to do it...
How it works...
Implementing Save and Save As events
Getting ready
How to do it...
How it works...
Implementing XAML Workflow Tab and Run events
Getting ready
How to do it...
How it works...
Implementing visual tracking
Getting ready
How to do it...
How it works...
See also
Index

Microsoft Windows Workflow Foundation 4.0 Cookbook

Microsoft Windows Workflow Foundation 4.0 Cookbook

Copyright © 2010 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2010

Production Reference: 1170910

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-849680-78-3

www.packtpub.com

Cover Image by Tina Negus (<[email protected]>)

Credits

Author

Andrew Zhu

Reviewer

Geert van Horrik

Ryan Vice

Acquisition Editor

Rashmi Phadnis

Development Editors

Dhwani Devater

Technical Editors

Gaurav Datar

Rukhsana Khambatta

Copy Editors

Janki Mathuria

Sanchari Mukherjee

Editorial Team Leader

Gagandeep Singh

Project Team Leader

Priya Mukherji

Project Coordinator

Leena Purkait

Indexer

Monica Ajmera Mehta

Proofreader

Chris Smith

Production Coordinator

Alwin Roy

Cover Work

Alwin Roy

About the Author

Andrew Zhu has six years of experience of software development and information technology: three years in Java, three years in .NET/C#. During these years, he designed and developed applications including computer language complier, SQL interpreter, Library book management application, online sale application based on JSF/Java, and SharePoint OA application. Two and half years ago he joined Microsoft. Since then, he has been helping developers solve IIS and BizTalk problems, developing .NET/Workflow/ASP.NET/SharePoint applications for his customers. Now, he is a Technology Support Engineer working in Microsoft (Microsoft Globe Tech Support Center), Shanghai. He has been supporting WF4 since its beta1 version.

No book is the product of just the author—he just happens to be the one with his name on the cover.

A number of people contributed to this book, and it would take more space than I have to thank each one individually.

I must thank my colleague Steven Cheng and Packt acquisition editor Rashmi Phadnis—without you, I wouldn't have a chance to write this book. Thanks to Packt Development Editor Dhwani and Project coordinator Leena. You two stayed with me throughout the writing process. I cannot imagine what could come out without your help. Also thanks to Technical Editor, cool Gaurav and Rukhsana Khambatta. My thanks also go to the Copy Editor of this title Sanchari Mukherjee.

I want to thank the reviewers of the book: Ryan Vice, Dave Newton, Geert van Horrik, and Ryan Andrus. Thanks for your patience and comments. Without your effort, the book would have been full of mistakes and incomplete.

I also want to thank my colleagues from Microsoft: XianFeng Zhang, Guang Yang, SGuy Ge, Steve Danielson, Nate Talbert, and Dan Glick. Thanks for your help in the WF and WCF 4.0 discussion list.

Finally, I want to thank my Mom and Dad, thanks for your love and understanding.

About the Reviewers

Geert van Horrik, after finishing high school in 2001, decided he wanted to learn more about software development. During his education as a software engineer in university, he wrote a some applications using Delphi. Soon, he discovered the power of C++ and started writing open source projects.

During his study, one of his open source projects became very popular, and he spent most of his time writing new features for this project. After finishing education in Software Engineering cum laude, he decided to learn some more about business administration at another university. However, the combination of his addiction to software development and the open source projects made him quit the new study and start a company called CatenaLogic.

The most important product of CatenaLogic is Updater—a tool to easily deploy new versions of software on all clients. Geert van Horrik is also available as a freelance software developer, and mostly concentrates on the latest technologies such as C# and WPF.

Geert also loves helping other people with software development problems on forums, and tries to participate in open source projects in the spare time he has left.

Ryan Vice is an enterprise programmer with 10 years of experience working with Microsoft Enterprise solutions. Over those 10 years, he has worked on network security systems, high-volume e-commerce systems, title management systems, and a high-volume financial trading application. Additionally he has built workflow solutions for a geoseismic system and for a credit counseling management system. He has worked with both thick and thin clients and is currently specializing in the WinFX suite of tools. He was given Microsoft MVP in 2010 for connected systems and is an MSDN moderator. He also frequently teaches classes on WF throughout Texas.

I'd like to thank my father Ken for being a huge inspiration in both my career and my family, my mother Telsa for helping me get my career started, my beautiful wife Heather for all her support and love over the years and willingness to let me spend a lot of my free time tinkering with software technology, my daughter Grace for reminding me of how amazing the simple pleasures in life can be, and my new-born son Dylan for bringing so much more joy and love into our lives.

Foreword

Microsoft has been putting a lot of resources toward the development of Windows Workflow Foundation (WF). Therefore, before learning this new framework, it's important to understand why Microsoft feels it is so important. For WF 4.0, Microsoft went back to the drawing board and did a complete rewrite of WF technology with the goals of improving WF 3.5 by providing a WF framework that simplifies the development of workflow-based solutions and provides better performance. Microsoft's ultimate goal is to get a higher rate of adoption of WF and to attempt to make WF an essential component of the enterprise developer's tool kit. The questions that most developers and architects, who are first exposed to workflow, will be likely to have are:

Why do I need it? Why does Microsoft feel it's so important to learn this new WF framework?What problems does WF make easier to solve to justify the non-trivial ramp up time for my team and me?

These are the questions that need to be answered before you start to learn the details of how to use the WF framework, as learning WF is not a small task and understanding the benefits would go a long way in helping motivate you and your team. This section of the book will help you better understand the "WHYs" of WF and lay the foundation for the rest of the book, which will allow you to hit the ground running by getting up to speed on the "HOWs" of WF. This book consists of short, easy-to-understand examples (or recipes) that show how to take advantage of the many benefits of WF. Your first read will allow you to get familiar with all the various features and extensibility points of the WF 4.0 framework and, as you implement WF 4.0 based solutions, you will find yourself coming back again and again to review these concise, easy-to-understand WF recipes. After reading this short book, you will be ready to simplify your enterprise development architectures by taking advantage of this powerful new workflow framework and all of its built-in, out-of-the-box features.

Let's get to it then… Why workflow? For starters, what kinds of problems does workflow make easier to solve? Let's suppose you need to build a solution for an accounting firm and that firm wants to have a system built to allow them to provide income tax services. This system needs to support the following features.

Account Creation: The system will allow clients to create accounts either by coming into a branch where an employee can create the account via a thick client application or by allowing the client to create the account via a website.Income Tax Information Submission: The system will allow clients to submit income tax-related information for review by an accountant either in a branch office or on the Web.Management of Assigning of Clients to Accountants: The system will allow for the automated assigning of clients to accountants with support for manual updating of assignments.Managing the Approval Process: The system will allow for managing the review and approval process involved in preparing income tax papers for submission to the IRS, including management of requesting more information from clients, following up with clients, and routing information received from clients to correct accounts.Notifications: The system will allow for notifying clients of various account and tax submission-related events.

How would a system like this be built without using a workflow framework? Our first attempt might be to create a set of web services that support:

Creating of a client accountSubmitting income tax information for an existing accountQuerying for income tax submissions assigned to an accountantQuerying for a specific tax submissionRequesting more information from the client about an income tax submissionApproving the information submitted to indicate that the income tax information is complete and ready for an accountant to make an income tax return to be submitted to the IRS

This income tax process could take several weeks or months to complete and so it's not feasible that we could have a thread on the server waiting for the next input for an account to arrive. For this application to scale and work with any type of realistic enterprise volume, we'd have to persist the state of the account and when each web service request arrives, we'd have to take some kind of identifier (account ID or accountant ID) and retrieve the current state of the account before we could determine if the call could proceed. A client can't submit income tax information before they've created an account and the service for submitting income tax information would have to query our persistence store (database or whatever we are using) to verify this. All of this custom state-management code that would allow for sharing the account data among the various client applications from the various servers would need to be written by the developers including ways to deal with concurrency. We can't allow two clients to update the same data at the same time, so we'd have to provide for that in our implementation.

Assuming we get all that worked out, what about the parts of this process that aren't driven by web-services calls? How are we going to assign clients to accounts after they submit their tax forms? How are we going manage our notifications that will be sent to the clients when:

We receive their informationWe approve or reject their informationWe need to request more informationWe've submitted their taxes to the IRS

We'd also need to build a scheduling system and an event routing (or messaging) system to help us satisfy these needs.

How do we deal with scalability? One solution would be to break apart the functional components of the application and deploy each one to a different server or set of servers so that you'd have a server for:

Creating accountsSubmitting tax dataAssigning accountants to clients

Using this approach would allow us to scale but would make the application logic separated and hard to understand and maintain, as it would be spread over several deployments on different servers.

The ideal solution would be to have a framework that would allow us to:

Build our workflow logic in a unified wayExecute our workflow logic in a distributed way, across several serversAllow for easy sharing of and persisting of state without having to worry about concurrencyAllow for easily creating events or messages that can drive business logic, including support for scheduling these events or messagesAllow us to track the history of an account

If we had a framework that allowed for all these things, then it might be worth our time to go out and learn how to use that new workflow framework as it would provide us a lot of built-in benefits that would save us from having to reinvent the wheel over and over again. The good news is that this is only part of what Workflow Foundation provides. In addition to helping solve these problems, WF also provides:

A re-hostable designer to allow us to create administration tools for visualizing and managing our workflow logicSupport for parallel processing of tasksSupport for creating our own workflow constructs (or activities) to allow us to model our own domain-specific languagesAn extensible architecture that allows us to provide our own implementations for things such as state persistence, workflow execution tracking, threading, and so on

Given all that WF 4.0 brings to the table, it's a worthwhile investment to learn this technology and add it to your enterprise development toolkit, and this book will help to get you up to speed in a very short amount of time.

Ryan Vice

MVP for Connected Systems

Preface

WF4 is a process engine, as well as a visual program language, shipped along with Microsoft .NET Framework 4.0. Traditionally, when we design a long-running application, we break a large application into lots of small code blocks to address the business logic and use a database to store the intermediate data. With the growing complexity of logic, managing code blocks and authoring logic workflows becomes difficult. Now, with WF4, we can design and create distributed, long-running programs easily.

The aim of this book is to provide a step-by-step guide to help us start WF4 programming. Every recipe in this book is runnable.

What this book covers

Chapter 1, Workflow Program, provides recipes that will help us understand basic information about WF4 programming.

Chapter 2, Built-in Flow Control Activities, provides recipes that demonstrate the usage of the built-in control activities.

Chapter 3, Messaging and Transaction, provides recipes that demonstrate how to send and receive WCF messages in workflow. The second part of this chapter focuses on applying transactions in a workflow program.

Chapter 4, Manipulating Collections, demonstrates how to manipulate collection data in workflow programs with WF4 built-in activities.

Chapter 5, Custom Activities, demonstrates how to create our own custom activities; the most powerful unit of workflow.

Chapter 6, WF4 Extensions, demonstrates how to use the built-in extensions such as persistence and tracking, and also how to create our own extensions.

Chapter 7, Hosting Workflow Applications, mainly explains how to host workflow applications in IIS7. This chapter also provides recipes that demonstrate host workflow in ASP.NET, WPF, and Windows Forms.

Chapter 8, Custom Workflow Designer, helps us create our own WF4 workflow designer with visual tracking function.

What you need for this book

We need a PC having Windows Vista/7/2008/2008R2. We can also use Windows XP, but it is not recommended. .NET Framework 4.0 is a must. Once we install .NET Framework 4.0, we can run workflow applications. To develop WF4 workflow applications, we should also have Visual Studio 2010 installed on our computer. To host WF4 as a WCF service in IIS, we should install IIS7/7.5 in our computer.

Who this book is for

If you find yourself working with Windows Workflow Foundation 4.0 and you have basic knowledge of C#/.NET Framework/VB and workflow, this book is for you. It will be best if you know both C# and VB, because WF 4.0 expressions can be written only in VB (at the time of writing). With this book, you will be able to enhance your applications with flexible workflow capabilities using WF 4.0. To follow the recipes, you will need to be comfortable with .NET Framework, C# programming, and the basics of SOA and how to develop them.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The ActivityLibrary project is for all customized activities, whereas the WorkflowConsoleApp project is used for testing our customized activities".

A block of code will be set as follows:

class Program { static void Main(string[] args) { WorkflowInvoker.Invoke(GetCodeStyleWorkflow()); }

Any command-line input or output is written as follows:

.NET Framework 4 Full (32-bit) – silent repair %windir%\Microsoft.NET\Framework\v4.0.30319\SetupCache\Client\setup.exe /repair /x86 /x64 /ia64 /parameterfolder Client /q /norestart

New terms and important words are shown in bold. Words that you see on the screen, in menus, or dialog boxes for example, appear in our text like this: "Click the