How to Resume Suspended Workflows in .NET WF 4.0

Wednesday, 28 April 2010 12:57 AM
by Coose

So we’ve been on WF 4.0 for a while now, and we have been anxiously awaiting Dublin (AppFabric).  One of the things we really wanted out of AppFabric was the ability to resume workflows that have suspended due to unhandled exceptions.

Well, I discovered that you don’t need AppFabric.  The sql instance store already gives us that functionality…there’s just no GUI for it (that I can find).

So, start by creating the databases.  The scripts are in the framework folder:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\SQL\en\SqlWorkflowInstanceStoreSchema.sql
C:\Windows\Microsoft.NET\Framework\v4.0.30319\SQL\en\SqlWorkflowInstanceStoreLogic.sql

Now, in the service behavior for the workflow xamlx, add some entries:

          <sqlWorkflowInstanceStore connectionStringName="Workflow"

                                    hostLockRenewalPeriod="00:00:05"

                                    runnableInstancesDetectionPeriod="00:00:02"

                                    instanceCompletionAction="DeleteAll"

                                    instanceLockedExceptionAction="AggressiveRetry"

                                    instanceEncodingOption="None" />

          <workflowIdle timeToPersist="00:00:02"

                        timeToUnload="00:00:05"/>

Make sure your connection string name matches your connection string to the database tables you created from the above sql scripts.

One more configuration item to add.  The workflow control endpoint needs to be added to the xamlx workflow service.

<service name="MyWorkflowService"

         behaviorConfiguration="myServiceBehavior">

  <endpoint address=""

            binding="customBinding"

            bindingConfiguration="myBindingConfiguration"

            contract="IMyContract" />

  <endpoint address="wce"

            binding="basicHttpBinding"

            kind="workflowControlEndpoint"/>

</service>

The endpoint with ‘kind=”workflowControlEndpoint”’ (new for .NET 4.0) is the key here.  That creates the workflow control endpoint on your workflow service.

Now, after I get an exception in a workflow (and on my development machine, there has been many), the InstancesTable in the instance store contains the information we need.  Running the sql:

select Id, SuspensionExceptionName, SuspensionReason, ExecutionStatus
from [System.Activities.DurableInstancing].InstancesTable
where IsSuspended = 1

I get these records:

image

So, here I can see the suspended workflows.  What I need from here is the Id.

Now, let’s call the endpoint we created above.  It’s a piece of cake:

You need a reference to System.ServiceModel.Activities v4.  On my machine it’s found at C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.Activities.dll.  This assembly contains the classes WorkflowControlEndpoint and WorkflowControlClient.

Guid workflowId = SelectWorkflowIdSomehow();

 

WorkflowControlEndpoint ep = new WorkflowControlEndpoint(

    new BasicHttpBinding(),

    new EndpointAddress("http://localhost/myWorkflowService.xamlx/wce")

);

WorkflowControlClient client = new WorkflowControlClient(ep);

client.Unsuspend(workflowId);

That’s it.  The WorkflowControlEndpoint does the work, and the workflow is unsuspended and resumed from the last persisted state before the exception happened.  Essentially, everything that happened between un-persistence and the exception is gone, and the previous state is loaded.

Cool, huh?  And you don’t even need AppFabric.  AppFabric does add a nice layer of UI for persistence and tracking, so I’m still looking forward to it! :)

Enjoy.  Or don’t.  Whatever.

Comment on this
Development
|

Comments (2) -

Pablo Rotondo | Reply
11/30/2010 10:08:26 PM #
Hi! great article!! this is what i need! however i have a couple of problems trying to configure the configuration endpoint correctly..

i'm getting the "AddressFilter mismatch" exception with this configuration... please can you post the behavior section and the binding configurations? thanks!!!

ps. sorry my english sucks! cheers from argentina!

Rameshwari | Reply
12/14/2010 7:52:36 PM #
I am getting some issue to resume the workflow , getting this error .
The message with Action 'schemas.datacontract.org/.../Unsuspend' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

My WCF WorkFlow Service contain 2 "receive and sendreply" activity . with an OperationName in it . Could you please provide me  the needful information .


Thanks

Rameshwari

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading