index > Windows Workflow Foundation > Serious design flaw in HandleExternalEventActivity?

Serious design flaw in HandleExternalEventActivity?

To set up the subscription for events from a custom service, CallExternalEventActivity registers with the CorrelationService, and calls the specified method on the custom service to create the event subscription.

When an event is raised by the custom service, it is handled by the HandleExternalEventActivity. When this activity is unsubscribed, it cleans up its own subscription with the CorrelationService, but it provides no means for the subscription with the custom service to be cleaned up, as there are no overridable unsubscribe method.

This means that subscriptions cannot be manually removed from custom services!

I appreciate that for once only guaranteed events, such as the CorrelatedLocalService sample this isn't a problem as the subscription cleans itself up when done, but for other things such as a file watcher service or message queue listener service, where the events are neither once only nor guaranteed, the subscriptions cannot necessarily clean themselves up (for example, the specified file system event may never be raised).

Now either I'm missing something (entirely possible) or this is a serious design flaw in the HandleExternalEventActivity activity. It looks as though it could be easily solved by declaring the private UnsubscribeForActivity as "protected virtual" but at the moment it is a major issue.

Any comments appreciated.

(note that at the moment, I have wrapped the HandleExternalEventActivity inside a SequenceActivity, implemented the IEventHandler and IActivityEventListener<QueueEventArgs> interfaces which pass through to the handler activities implementations, and added my custom unsubscribe code to the Unsubscribe and Execute methods. This also required me to write a custom CorrelationTokenType converter as the provided one is internal, so it hardly seems an ideal solution although it does appear to work fine)

Greg Beech
I guess I'd agree with you if HEE/CEM and the subscription services were intended to be extensible. My understanding is that you either use HEE/CEM as they are out of the box *or* build your own activities that use WorkflowQueues directly.


http://www.quicklearn.com/workflow.htm
Jon Flanders

The CorrelatedLocalService SDK sample derives from these activities, which implies that they are intended to be derived from in this type of case.

The particular activity I am writing here is a file system watcher, which needs to be in two parts as the first activity needs to start the watcher, then the code needs to occur which may cause the file drop, and then the second activity receives the event if it occurs. The SDK sample where the same activity sets up the file watcher as listens for its events is subject to a race condition where the file drop may occur before the watcher is set up.

To go down the manual workflow queue route, I would essentially going to have to write my own correlation service to buffer the events between when the first activity sets the FileSystemWatcher up and the second subscribes to these events, and try and reproduce all the handler logic in HandleExternalEventActivity. This is not a trivial task.

My workaround, which was easier than this but still nontrivial is to host the HandleExternalEventActivity in my own listener and insert calls to my custom unsubscription logic where needed, which was the in Unsubscribe, Execute and Cancel methods, before passing through to the hosted activity. In fact, exactly where the private unsubscription method is called in HandleExternalEventActivity itself.

It seems to me flawed that there is no way to hook into when the underlying activity is being unsubscribed, given that the two activities give you explicit means to subscribe and handle events, and that from my testing all that is needed is one private method to be made protected virtual.

Greg Beech
I haven't seen that sample - but i still would stick with my assertion that once you find HEE limiting you are better off going directly to queues.


http://www.quicklearn.com/workflow.htm
Jon Flanders
btw - that is just my own personal opinion.


http://www.quicklearn.com/workflow.htm
Jon Flanders

Jon,

I agree with you. The HEE activity concept is based on the event driven wrapper around the remoting IMethodCallMessage messaging with tightly coupled design pattern to the business layer. Raising an ExternalDataExchange event in the business layer will create an IMethodCallMessage message and enqueue it to the private application specific workflow queue (created based on the interface type, method, ...).

Using the WorkflowQueues directly enables consuming a workflow based on the interface contract. That's why I have built this.




Roman Kiss, MVP Connected System Developer
Roman Kiss
Greg,

I would agree with Jon that if you're feeling too limited by the HEEA support, you'll want to implement your own event activity. I would also agree with you that this is more complicated, for sure, and the documentation at this point is somewhat lacking.

FWIW, I have a two part article on implementing custom event activities that might be useful:
http://www.winterdom.com/weblog/2006/02/28/WFEventActivities1.aspx
http://www.winterdom.com/weblog/2006/03/05/WFEventActivities2.aspx

There's also a sample Custom Activity Framework on the WF community site that has support for builind event activities. I haven't used it myself, but it should probably make it easier to get started:
http://wf.netfx3.com/files/folders/activity_behavior/entry838.aspx




Tomas Restrepo [MVP]
Tomas Restrepo

Thanks for the input guys, I'll have a look at the articles and samples you've suggested.

Maybe it's the lack of documentation but I guess I just didn't feel that you should have to write a custom framework for subscriptions given that there is built in stuff which seems targeted at doing this. It seems rather weak that more generally useful framework code isn't actually part of WF in the first place, only limited activities. Oh well - I guess it is essentially a V1 product... :-)

Greg Beech
You are allowed to derive from HEE or CEM so that you can hardcode the InterfaceType and EventName/MethodName and have properties associated with the parameters on the event / method built on the activity. If you want to do anything else you will need to use WorkflowQueues directly as Jon and others have stated.


MS Workflow SDE/T - This posting is provided "AS IS" with no warranties, and confers no rights.
Tom Lake
reply 9

You can use google to search for other answers

 

More Articles

• Invoking WebServiceInput directly....
• Why DependencyProperties ?
• WinWF Beta 2.2 SqlDatabaseActivity with invalid ConnectionString ...
• Automatically Binding Properties at Design Time
• how does the instanceId get set on SqlWorkflowPersistenceService
• State Machine SQL Tracking DB: How to find Executing activities t...
• Duplicate activity name error when dynamically adding a custom co...
• Properties of Workflow in Designer
• How do you scale WWF Beta 2.2 Workflow Runtime service?
• Generating ruleset in runtime
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Workflow projects in VB Express: any mak
• e-book about workflow foundation
• When is CancellationHandlerActivity exec
• Is there any Comprehensive guide for Win
• Embedded designer and custom activities
• Please help with URLs to get started
• Load a custom activity designer in the d
• workflow s/w seggregation
• Could I use WWF in such scenario?
• How to get ActivityExecutionContext from
• Serializing generic collection propertie
• synchronizing with workflow thread
• Workflows and returning data
• state engine design question
• Message Queue Error: "QueueExists&q

Hot Articles

• How can i get refference of Workflow Run
• Implementing IDynamicPropertyTypeProvider
• Workflow Designer on ASP.NET app
• Code samples for Workflow Designer hoste
• State machine usage
• How to persist a workflow
• Internal Statement Parser
• Chaining Workflows Synchronously
• Trouble with WebService and Persistence
• hi james ,about your asp.net web apps
• What Windows Workflow Foundation can do?
• Getting URL from a workflow hosted in AS
• A question for state machine workflow
• workflow and web apps
• WebServiceInput Activity Error: Paramete

Recommend Articles

• StartWorkflow() function - ss.RunWorkfl
• Sequential Workflow Cancellation
• Problem Using ifElseactivity in an Embed
• custom activity
• Trouble with a while condition in a win
• Would this be a useful technology for th
• How to run a extra workflow defined by e
• Timers Persistence with Default and Manu
• DataExchangeService Attribute in Beta 2.2
• synchronizing with workflow thread
• multi choice pattern
• WF Designer Host Example
• How to get WPF and WF work together?
• Creating Execution Contexts
• Setting return value for List<string&