Passion * Technology * Ruthless Competence

Friday, November 03, 2006

Slight Workflow Annoyance

One of the cool things about WF is that you can specify the Guid it uses to identify a workflow instance. WorkflowRuntime.CreateWorkflow has an overload (actually two) where you can specify said workflow instance identifier. This is awesome for using WF with Service Broker, as Service Broker already has the idea of a conversation group which is roughly analogous to a workflow instance. Conversation groups even use a Guid identifier, so there's not even any mapping required to go from conversation group to workflow instance.

However, things get less cool when you call WorkflowRuntime.GetWorkflow. If you call GetWorkflow with a Guid that has no corresponding workflow instance, it throws an InvalidOperationException instead of just returning null. That seems like an odd choice. If you're going to support specifying the instance identifier when you create the workflow instance, doesn't it make sense that you should also gracefully support the scenario where an instance identifier is invalid?

I see two ways to deal with this:

  • Iterate through the list of loaded and persisted workflow instances looking for the one in question.
  • Call GetWorkflow and swallow the exception.

I ended up picking the "Swallow the Exception" approach as I can't imagine the iteration thru every loaded and persisted instance would be very performant. But swallowing exceptions always makes me feel icky. I'm a fan of the "exceptions only for exceptional situations" approach and as far as I'm concerned, an invalid instance identifier isn't that exceptional. Still, it's a minor annoyance, especially given how cool it is to be able to specify the workflow instance identifier in the first place.

Posted By Harry Pierson at 11:36 AM Pacific Standard Time
Friday, November 03, 2006 12:10:25 PM (Pacific Standard Time, UTC-08:00)
I'd respectfully tend to disagree. I am a firm believer in the idea that exceptions should be thrown when a method can't perform the operation which is implied by its name. (This is a bit more concrete than the "exceptional condition"). Which now means that the semantic implication of "get" (as in GetWorkflow) is the thing we'd need to argue about. Here, I usually tend to prefer the pattern that get/load/retrieve-methods do indeed throw an exception if the can't get the specified item (after all, they couldn't do what their name implies) whereas methods like FindWorkflow() - if they would exist - would happily return empty lists if there were no matches for the given criteria. In essence, I would have expected the WF runtime to perform this operation exactly in the way it does.

Just my 2c,
-Ingo
Ingo Rammer
Comments are closed.

PDC08

patterns & practices
Summit 2008

Øredev

Change Congress
Recent Bookmarks
Tags .NET Framework (2) ADO.NET (5) Agile (7) AJAX (3) Architecture (284) Guidance (6) Interop (2) Modelling (61) Patterns (7) Process (4) SOA (93) Web Services (5) ASP.NET (24) Battlestar Galactica (3) BI (2) BizTalk (4) Blogging (115) dasBlog (11) Podcasting (4) BPM (1) C# (10) C++ (4) Capitals (5) CardSpace (3) CLR (2) College Football (10) Comedy Central (1) Community (81) Concurrency (6) Consumer Electronics (1) Database (13) Dependency Injection (2) Development (117) C Plus Plus (1) Embedded (5) Lanugages (37) Media (2) P2P (11) Rotor (1) SharePoint (6) SOP (3) DIY (1) DLR (14) Domain Specific Languages (13) Durable Messaging (5) Dynamic Languages (10) Dynamic Silverlight (1) Education (3) Enterprise 2.0 (1) Entertainment (14) ETech (15) F# (51) Functional Programming (17) Game Development (2) Guidance Automation (3) Hardware (8) HawkEye (3) Hockey (29) Home Electronics (1) Home Network (5) Humor (5) IASA (1) Idempotence (3) infrastructure (5) Instrumentation (4) Integration (2) IronPython (27) IronRuby (11) Java (2) Job (3) LINQ (19) Live Mesh (2) Lost (1) Master Data Management (1) Media 2.0 (6) Microsoft (29) MIX06 (2) Mobile Phone (1) Monads (5) Morning Coffee (172) Object Oriented (4) Office (5) Open Source (5) Open Space (2) Operations (3) Other (135) Art (1) Books (1) Family (31) Games (18) General Geekery (26) Home Theater (1) Movies (23) Music (20) Politics (3) Society (1) Sports (37) Working at MSFT (15) Parsing Expression Grammar (16) patterns & practices (2) PDC08 (2) Politics (42) PowerPoint (2) PowerShell (33) Presentation (5) Projects (1) HawkWiki (1) Python (4) Quote of the Day (4) Refactoring (1) Research (2) REST (18) Reuse (5) Robotics (2) Rome (5) Ruby (23) Ruby on Rails (1) Sci-Fi (2) Scripting (4) Security (3) Service Broker (14) SharePoint (2) Silverlight (18) Social Software (1) Software + Services (2) Software Design (1) Software Factories (11) Software Industry (1) Spark (1) SQL Server (2) Stephen Colbert (1) TechEd (7) TechEd06 (1) TechRec League (1) Television (6) Travel (6) Unified Client (1) Unit Testing (4) UX (1) Virtual PC (2) Visual Basic (1) Visual Studio (20) Volta (2) Washington Capitals (34) WCF (31) Web 2.0 (65) Web Services (5) WF (21) Windows Live (23) Xbox (1) Xbox 360 (53) XML (7) XNA (14)
Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion.