Sample to understand basic local communications in Workflow

by Matt Milner 2. April 2006 19:31
I've been teaching a lot of folks workflow as part of the Longhorn Server Ascend training and the simple example that I was using just didn't cut it.  So, I put together a set of example applications to show how the basic local communications work.  The main thing I wanted to show was how the use of an interface as the contract between your workflow and your host, allows you to swap out different hosts and provide different implementations of the local service, without the workflow having to know or care about any of this.  The workflow simply looks for a service that implements the right interface, and then calls into that class based on the interface. 
 
So, I created three different implementations of a VERY basic coffee machine: console, WinForm and ASP.NET.  The sample shows how you can simply add the right type of service implementation for your host and the workflow can be used in a number of environments.  The code is pretty well commented so you should be able to follow along. 
 
This works on WF 2.0 (Feb CTP).  Everything except the ASP.NET application will work on the 2.2 release as well.  I'll provide an update here when I get the ASP.NET example ported over to 2.2 later this week. 
 
Any feedback or questions are welcome.  Enjoy. 
 
The 2.0 compatible code is here.
I've uploaded the 2.2 compatible code here.
 

Tags:

Windows Workflow Foundation

Using data driven workflow activities and repeated correlation

by Matt Milner 21. February 2006 06:11
How's that for a title?  The driver for this post is that I'm training a lot of folks right now on using WF to build workflows, and when we cover correlation, the example we use has two branches in a parallel activity where we correlate within each branch.  The question inevitably comes up about how to do this dynamically, where the number of "branches" is driven by data.  So, I whipped up this example that uses code from the Microsoft Windows Workflow Foundation Labs (Beta 2) to showcase the Replicator Activity and the Conditioned Activity Group (CAG).  These two activities provide for richer models of business rule or data driven replication using correlation. 
 
In order to enable my example, I have created a composite activity that wraps up the voting behavior found in the communications lab.  This gives me a reusable component that I can then use in multiple places in my workflow, and it also gives me the ability to set properties on the set of activities (now my single composite activity) for each instance.  For example, one of the key properties I can set is the alias, or name, of the user who should vote.  In addition, I can define events at the composite activity that my workflow can listen for and handle.  This allows my workflow to take action when a voter approves or rejects a ballot. Finally, I define a correlation token within the activity and set the parent activity to the composite activity itself.  This provides the context in which my correlation token is valid and is the key to allowing me to correlate within each activity.  Note that it is not required that you do this in a composite activity, the parent activity for your correlation token can be a sequence or some other container.  Finally, I added a property to my workflow called Aliases of type List<string>  which holds the data for my workflow.  I pass in this data from program.cs via parameters to the workflow. 
 
In my workflow, I have two main activities, the first is a replicator which shows how to use this activity to do data driven correlated activities, and the second is the Conditioned Activity Group which allows you to use rules/conditions to determine what branches of activities to run, and when I am done running them. 
 
The replicator activity in my example has the InitialData property bound to the workflow property for aliases, so I am going to run whatever activities are in the replicator as many times as I have items of data.  I also need to pass that data to each instance of the voting activity before it is executed (specifically, the alias it should use).  I use the Child_init event on the replicator to set the alias based on the current data item.  The current data item lets me get the current item in my collection of data and I can then use that to configure the currently executing activity or set of activities.  I also set the execution type property on my replicator to indicate if I want all the branches to run in parallel, or in sequence.  Very powerful option!
 
For the CAG, I have included two voting activities, and bound their aliases to two different instances of input data on the workflow.  I've done this using indexed values from the List<string> property.  When dealing with a CAG, you have to set the "when" property on each branch of execution which indicates the rule or code to determine if the particular branch should execute.  On the CAG itself, you provide a "Until" property that likewise specifies code or rules, but these provide the condition under which execution should stop.  So, the CAG will continue running (foreach/while style looping) until the "Until" condition is met. On each interation, it will use the "when" condition on each activity branch to determine whether it should run that branch.  So you get replication, but with rules to guide it.  You get a lot more than that, but this is a simple example. 
 
When you run the program, it might help to disable one activity and focus on the output by the other.  Running the replicator will give you three vote dialogs, each with the appropriate users name, and the console will appropriately log their votes.  We correlate the response back into the workflow on each instance of the votingactivity.  When you run the CAG, you'll see that the first time through, both voting activities will run.  Until you vote "yes" on one of the items, the CAG will continue to run and use the "when" condition to determine which activity branches to run.  Play around with your voting and notice what happens if you continue to vote no with one person for a few rounds, then vote yes.
 
The final thing to notice is that we have a need to catch the situation, with our CAG, where someone voted yes, but the other person has not yet responded.  If we don't deal with this scenario, when the second person votes, they will get an exception.  We use the WorkflowQueueInfo data from the workflow instance to query the workflow and see if it is waiting for any responses.  If it is not, then we gracefully exist instead of trying to raise the event.  If it is, then we go ahead and raise the event.  This is one way you can attempt to avoid the EventDeliveryFailedException. 
 
Hopefully these examples will prove useful for someone.  I plan to do my best at creating more examples to share.  As always, feedback is welcomed.  You can get the code here
 

Tags:

Windows Workflow Foundation

&amp;quot;Beta 2&amp;quot; of WinFX (WCF, WPF and Workflow Foundation) has arrived

by Matt Milner 18. January 2006 09:47
The Jan CTP for these products is now up on the Microsoft website and they even have go live licenses available!  I know a lot of people are eager to get a look at the updates, especially with workflow, so let the downloading begin!  http://msdn.microsoft.com/winfx/getthebeta/golive/default.aspx

Tags:

Windows Workflow Foundation

Week of Workflow Webcasts

by Matt Milner 15. September 2005 03:05

If you are interested in finding out more about Windows Workflow Foundation (WWF) then you should check out the upcoming week of webcasts.  See Paul's Blog for more details. 

Tags:

Windows Workflow Foundation

Windows Workflow Foundation- What about BizTalk?

by Matt Milner 14. September 2005 12:42

So, with the big announcement about the upcoming release of Windows Workflow Foundation (WWF - gotta love that acronym; I was surprised not to see Hulk Hogan here presenting), many BizTalk developers have already started asking what this means for BizTalk Server. 

The simple answer is that BizTalk 2008 (or whatever the official name becomes, but not 2006) will host the workflow runtime for its orchestration capabilities and will extend workflow with all of the great things you've come to expect from BizTalk.  BizTalk Server will be your enterprise solution for scalable, reliable message based integration, business process management and SOA applications and services.  BizTalk will be providing MANY important features on top of the basic workflow foundation that you will want for your EAI, B2B, and SOA apps, like pipelines, adapters, management, infrastructure, security, etc.  So, before you run off and say, "With WCF ("Indigo") and WWF, I can build my own BizTalk"; think twice, or maybe five times.  The BizTalk team has years of experience and customer data points for building the manageability, scalability and reliability that an application of this type demands and they will continue to deliver a product that goes far beyond the capabilities of the WWF. 

However, the great news is, skill sets in WWF, which will likely reach more developers, will be greatly applicable to BizTalk Server 2008 development.  And, because the workflow foundation is extensible, it is likely that BizTalk developers will get their biggest wishes answered in two ways.  1) BizTalk Server 2008 will almost definitely include VS.Net debugging for orchestrations as this is already built into WWF. 2) BizTalk 2008 will easily have the ability to allow developers to create and use custom actions, and we'll have to watch for the product team to include. 

All that being said, and my passion for BizTalk being obvious, WWF is hugely powerful framework on its own and will allow developers to create amazing applications while improving their productivity.  The activity model will also help in the ever present goal of making reusable components.  So, I'm very excited about WWF, and glad we can now talk about it publicly.  Look for more information here on my blog and the Pluralsight web site for upcoming announcements related to WWF, WCF and BizTalk. 

 

Tags:

BizTalk Server | Windows Workflow Foundation

Pluralsight Developer Training

View my developer training videos on Pluralsight.

Pluralsight Hardcore Training