Screencast: Using persistence services in Windows WF

by Matt Milner 1. October 2008 07:32

My latest screencast in the Windows WF developer screencast series has been loaded up as of this morning.  In this session, I discuss the basics of add persistence services into the workflow runtime using code or configuration.  Additionally, to show off the power of this feature in Windows WF, I use two different host processes sharing a persistence store: the first host starts a workflow and then it persists, while the second host picks up the workflow after its configured delay and resumes the processing.

 

Endpoint Screencasts - Using Persistence Services in Windows Workflow Foundation (WF)

 

WF_Persistence

 

Previous screencasts in this series:

  • Running workflows in your .NET applications
  • Your first state machine workflow
  • Your first sequential workflow
  •  

    RSS feed of all screencasts in the series

    Tags:

    Windows Workflow Foundation

    Screencast: Running workflows in your .NET applications

    by Matt Milner 24. September 2008 09:04

    My latest screencast is up on the Endpoint.tv show on Channel 9.  In this screencast I cover the basic steps to host workflows in your applications.  I cover the basic hosting steps in a console application, then jump in and run a workflow in an ASP.NET application. 

    Screencasts: Running Workflows in your NET Applications

     

    RunningWFInNetApps

     

    Previous screencasts:

     

    RSS feed of all screencasts in the series

    Tags:

    Windows Workflow Foundation

    Screencast: Your first state machine workflow

    by Matt Milner 23. September 2008 11:00

    In the latest screencast in the ongoing series, I cover the basics of creating a state machine workflow. I show you the various activities to use, how to transition between states and handle events including time based events. 

    Screencast: Creating Your First State Machine Workflow

     

    First state machine workflow

     

    Previous screencasts in the series:

     

    RSS feed for all screencast posts

    Tags:

    Windows Workflow Foundation

    Screeencast: Your first sequential workflow

    by Matt Milner 23. September 2008 10:11

    As Aaron pointed out a while back, Pluralsight has joined up with the WCF / WF folks at Microsoft to create a series of screencasts to give developers an introduction to these technologies.  My first contribution to this effort is all about creating a your first sequential workflow.  The screencasts shows the basics of creating the workflow, adding activities from the framework and custom activities. 

     First sequential workflow

    RSS feed for all WF screencasts

    Tags:

    Windows Workflow Foundation

    WF and WCF resources

    by Matt Milner 15. September 2008 02:09

    I just found out about a few new resources that Microsoft has put together to help developers locate relevant information for developing applications using WF and WCF. This includes some of the screencasts that Aaron and I have been doing on those technologies.  It is nice to have this information in one place and provides a great jumping off point for people wanting to learn about these great technologies. 

     

    Endpoint.tv (the home of our screencasts and other podcasts) -  http://channel9.msdn.com/shows/Endpoint/

     

    WF on the MSDN Social Server

     

    WCF on the MSDN Social Server -

     

    In addition, we are Pluralsight attempt to keep our resource pages for this stuff up to date with articles books etc. on our Wiki.  The links to those

    Pluralsight's WCF wiki - http://pluralsight.com/wiki/default.aspx/Aaron/WindowsCommunicationFoundationWiki.html

    Pluralsight's WF wiki - http://www.pluralsight.com/wiki/default.aspx/Workflow/HomePage.html

    Tags:

    Windows Workflow Foundation | Windows Communication Foundation

    Code Samples from todays webcast

    by Matt Milner 26. June 2008 18:01

    For those of you who attended my webcast today on workflow communications, the demo code is attached to this post. It includes the base activities used for communication activities (more on these in a later post) and it provides simple example of local communications and web services. The two-way communication activity and sample is also included. 

    If you are interested in the webcast check here in the next day to two for the OnDemand link.

     

    Enjoy!

     

     

     

    Tags:

    General Musings | Windows Workflow Foundation

    Upcoming talks and webcast

    by Matt Milner 9. June 2008 08:28

    I've got a couple of fun talks coming up this month.  First, I'm going to be doing an MSDN webcast on Windows Workflow Foundation - Communication in Depth.  I'm going to dive into the core communication architecture, discuss how some of the OOB activities use it, and how you can build your own activities to take advantage of it.  We'll cover one way communication between the host and the workflow, but we'll also look at how to do two-way communication to get a response back from the workflow. 

    The talk information can be found at this link:

    Windows Workflow Communication in Depth

    This talk is also part of a series where you can find other talks from my friends Jon Flanders and Jesus Rodriguez on other .NET 3.5 topics.  The link for the series is here:

    http://www.microsoft.com/events/series/msdnnetframework35.aspx?tab=webcasts&id=liveall

     

    I'm also doing a local talk this month at the Microsoft office if you are in the Minneapolis area.  I'll be talking about building connected systems with WF and WCF for developers and architects.  This will be a good talk if you are interested in these technologies and want to learn more about how to use them to build real applications. 

    Event information and registration

    I had a great time at Tech Ed and I'm looking forward to the conferences coming up this fall (Minnesota Developers Conference where I'll be doing talks on LINQ and ADO.NET Data Services and Heartland Developers Conference where I'll be talking about BizTalk Services and the "Internet Service Bus"). 

    Tags:

    General Musings | Windows Workflow Foundation | Windows Communication Foundation

    Not just a service pack (VS 2008 and .NET 3.5 SP 1)

    by Matt Milner 12. May 2008 12:50

    Microsoft has rolled out the beta of SP1 for .NET Framework version 3.5 and Visual Studio 2008.  Now don't get confused, this is not just a simple set of bug fixes, this thing is big! 

    • Entity Framework and LINQ to entities
    • ADO.NET Data Services (formerly project "Astoria")
    • Dynamic data web sites (highly RAD data driven web sites)
    • Performance improvements across the board (WCF, WPF, AJAX, debugging, etc.)
    • New client profile (not quite the slimmed down CLR of silverlight, but gives you a smaller footprint without server technologies you don't need).  Now, if they could do the opposite and remove the Windows UI stuff so I could run Windows Server 2008 Server Core with IIS and ASP.NET. 
    • a bunch of perf and usability improvements in VS 2008

    I think the Entity stuff, plus the Dynamic data and data services is a killer combination for many web site developers to get their data modeled and quickly expose an admin tool for data maintenance  and service endpoints for interaction. 

     

    Check out Soma's blog for some high level details and download links:Visual Studio 2008 and .NET FX 3.5 SP1 Beta available now

    Scott Gu has details on many of the new features in the IDE and framework: http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx

    Brian Harry has the details on the TFS improvements in the SP: Team Foundation Server 2008 SP1 Preview

     

    A metric b*#&load of enhancements for a service pack - awesome job folks, I can't wait for the released bits this summer. 

    Tags:

    General Musings | Windows Workflow Foundation | Windows Communication Foundation

    Spaghetti Code Podcast - Connected Systems

    by Matt Milner 12. May 2008 10:56

    I got a chance a few weeks ago to sit down with Jeff Brand at the local Microsoft office and talk about something I love - Connected Systems.  We discussed Workflow and Biztalk, WCF and web services and how it all fits together.  Jeff is fun to talk to and does a good job of asking questions that developers are interested in.  The issues most developers face when building connected systems and trying to pick technologies were especially fun to discuss.  If you are interested, check out the audio - http://www.slickthought.net/post/2008/05/Spaghetti-Code-Podcast---Matt-Milner-on-Connected-Systems.aspx.

    You can also check out some of his other podcasts with more Minneapolis folks on a range of topics: http://www.slickthought.net/category/SpaghettiCode.aspx

     

    Enjoy!

    Matt

    Tags:

    BizTalk Server | Windows Workflow Foundation | Windows Communication Foundation

    Updating the Retry Activity - adding timed interval

    by Matt Milner 28. November 2007 14:19

    Updated 11/29 - see below

    I recently created a retry activity that I've been wanting to write for some time now, and had a few features that I wanted to add. I was teaching a class a couple of weeks ago and took the opportunity to add a retry interval to the activity.  The activity is designed as a composite activity which can retry its child activities if it detects that a fault/exception has occurred.  Rather than retrying immediately, I wanted the consumer of my activity to be able to specify a TimeSpan indicating how long to wait between retry attempts.

    The simplest part was adding a property that allowed people to specify the interval. 

    private TimeSpan retryInt;
    
    public TimeSpan RetryInterval 
    {
        get { return retryInt; }
        set { retryInt = value; }
    }
    

     

    The next step was to actually use this information.  When the child activity closes, my Retry activity checks if it faulted and then needs to reschedule the child activity for execution.  With the interval, I need a way to wait for a duration and then schedule the activity for execution.  Since my workflow could be persisted during this interval, I have to use a mechanism that will both support passivation, and allow for the workflow to be resumed automatically when the duration has been reached.  To support this I used the same mechanism that the delay activity uses, which is to create  timer subscription and then wait for an event signaling the time has expired. 

    In my event handler for closing child activities, if I determine that I should retry the child activity, I use the following code to 1) create a new workflowqueue where the timer can signal completion, 2)register for data arriving on the queue, 3) create a TimerEventSubscription with my duration and my queue information and 4) add my timer subscription the collection on the workflow. 

     

    DateTime expires = DateTime.UtcNow.Add(RetryInterval);
    SubscriptionID = Guid.NewGuid();
    thisContext.GetService<WorkflowQueuingService>().CreateWorkflowQueue(SubscriptionID, false).QueueItemAvailable += new EventHandler<QueueEventArgs>(RetryActivity_QueueItemAvailable);
    TimerEventSubscription subscription = new TimerEventSubscription(SubscriptionID, WorkflowInstanceId, expires);
    TimerEventSubscriptionCollection timers = GetTimerSubscriptionCollection();
    timers.Add(subscription);
    

     

    The GetTimerSubscriptionCollection simply grabs the collection from the parent workflow by recursively climbing the parent hierarchy. 

     

    private TimerEventSubscriptionCollection GetTimerSubscriptionCollection()
    {
        Activity parent = this;
        while (parent.Parent != null)
        {
            parent = parent.Parent;
        }
        TimerEventSubscriptionCollection timers = (TimerEventSubscriptionCollection)parent.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty);
        return timers;
    }

     

    Finally, I have the event handler for when data arrives on the queue for the timer.  I simply empty and delete the queue, then begin my next iteration on the child activity. 

     

    void RetryActivity_QueueItemAvailable(object sender, QueueEventArgs e)
    {
        ActivityExecutionContext ctx = sender as ActivityExecutionContext;
        ctx.GetService<WorkflowQueuingService>().GetWorkflowQueue(e.QueueName).Dequeue();
        ctx.GetService<WorkflowQueuingService>().DeleteWorkflowQueue(e.QueueName);
    
        BeginIteration(ctx);
    }

     

    So adding a retry interval turned out to be pretty simple and I was also able to provide a good example of how you can put your own delay into your activities.  In a later post, I'm going to talk about the other issue I had to manage which is how to deal with exceptions and control whether or not my Retry activity got put into the faulting state. 

     

    BEGIN UPDATE

    Someone posted a question on the original activity indicating some concern over the fact that I hadn't overridden the Cancel method.  In the simpler scenario I should have still done that, but with the addition of my retry interval it became even more important as I had more to clean up.  So I added the Cancel method and do two things in it.  First, I had to see if there were any spawned execution contexts that were currently executing indicating that I had an iteration in progress and cancel the root activity if I did.  I also had to add some code to remove the timersubscription in both the expected case and the exception case.  In the process, I factored some code into a helper method to remove the timer subscription and the workflow queue when I no longer needed them.  The cancel method now looks like this:

    protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
    {
        bool canClose = true;
        ActivityExecutionContext ctx = executionContext;
        //cancel any execution iteration
        if (ctx.ExecutionContextManager.ExecutionContexts.Count > 0)
        {
            ctx.ExecutionContextManager.ExecutionContexts[0].CancelActivity(ctx.ExecutionContextManager.ExecutionContexts[0].Activity);
            canClose = false;
        }
        //remove the timer and related queue if there is a subscription
        CleanupSubscription(ctx);
        return canClose ? ActivityExecutionStatus.Closed : ActivityExecutionStatus.Canceling;
    }
    Notice that I can only close the activity if the child is not currently executing.  If I had to cancel the child activity, then I can't yet close the retry, that will happen in the usual way when the child activity closes.  The other important step I added was to check the current ExecutionStatus of the retry activity before scheduling a new iteration.  If the activity has moved into the Canceling state, I shouldn't start a new iteration regardless of how many times I am supposed to retry. 

    If you have any other feedback or suggested improvements, keep them coming. 

    END UPDATE

    The updated retry activity can be found here, and has been updated for Visual Studio 2008.  If you want the updates for 2005, just download the original, and then copy the class file for the retry activity from the new project.  I didn't use any new features of 2008, just updated the project and solution files, so it should work fine. 

    Tags:

    Windows Workflow Foundation