A first play with WinFX Windows Workflow

Ok - I admit it - I haven't really played with it - but my colleague Mike Taulty has - and I found it an interesting read. Check out his full post  on his experiences with Beta 1 or the highlights here:

"Now, I'm not a Workflow zealot in that I think WF is applicable to some application types and not necessarily applicable to others but the joy of WF is that where you do need workflow then the WF provides a very rich framework for implementing it in your application without have to write a few 100K lines of code just to get started. 

What I like about Workflow is that it doesn't try and be too clever for you. It presents both a design model and a code model so if the designer was to get something wrong (or not support something that you want) then you can just go ahead and add code to achieve it.

The extensibility model seems right in that I can write a custom Activity in 5 or so lines of code but it's also rich enough to support my own serialization, validation, design-time, execution and code-generation should I need to do it - i.e. low barrier of entry to a very rich environment. 

I also like the "communication" between my activities in that it's not some special (limited) pipeline that carries data from one Activity to another but, rather, the Activities are just composited into a Workflow class and so can communicate through properties that the Activities expose/consume.

I hosted a Workflow in a few different kinds of apps and found it pretty easy to do - I liked the "shared interface" model that underpins communication between a Workflow and its host and I found that really easy to implement. I also found it pretty easy for a host to get hold of a running instance of a Workflow and play around with it - took me about 30 mins or so to figure out how to do that and code it up.  

What struggles did I have? Not so many. I struggled quite a bit with the condition editor in trying to set up rules - clearly, it's a preview and it's not finished yet and you can feel that in places but it's very usable.

I also struggled with a bogus compilation error "Check if condition is defined in the conditions file" that kept coming out of my Workflow - you can find the details here and once you know that you can ignore it then you're ok but I spent maybe 2 hours trying to figure out what I'd done wrong before I realised that I hadn't done anything wrong :-) 

The other surprise that I had was that Workflow doesn't have built-in activities for calling/consuming WCF services out of the box. There seem to be 3 approaches to this right now;

1) Write your Workflow host so that it hosts a WCF service or consumes one (probably with a proxy). Share an interface between the host and the Workflow. That interface would have something like a CallService method and perhaps a ServiceCallReceived event and you'd implement it in your host app. Then, when the Workflow wants to make a service call it just uses CallService on your host and when a message is received the host will fire CallService into a Workflow. This is achieved in the Workflow through the InvokeMethod and EventSink shapes. 

I played with this and it worked a treat for me - found it very easy. The one thing you'll need is some kind of correlating token so that the host knows which Workflow instance to fire the event into. I used the Workflow ID as the token here (it's a GUID).

2) Write some generic WCF custom Activities - e.g. "Send SOAP Message" and "Receive SOAP Message". You'll need to perhaps write these in terms of IOutputChanel, IRequestChannel and so on and they'll need to take instances of the Message type or similar. 

3) Write some specific WCF custom Activities - e.g. "CallCustomerService", "ReceiveInfoFromCustomerService". You'd write these using the higher level WCF APIs so it'd be less work than (2) but you'd need different classes for each service that you interact with.

So - you can make it all work and it's pretty easy but it'd be nice to have WCF Activities in the Workflow box and I'd guess that if they don't get in there because of timescales then some samples will probably spring up."