Wednesday, February 18, 2009

Workflow 3.5 Designer Rehosting

Since the release of Workflow, Designer Rehosting has been promoted as one of the good qualities of Workflow. In each article or presentation Designer Rehosting keeps coming back as a good thing. So I decided to put it to the test. I started with trying to find a reason why a customer would want to use Designer Rehosting. Microsoft gave me the following reasons:

  • (Design Time) To view, create or modify Workflows
  • (Runtime) To view the current state of an executing workflow by utilizing the tracking information.

Both reasons are obvious and still don't give me any reason to sell it to a customer, they can use Visual Studio to do exactly the same. There's another reason why your customer might want to use Designer Rehosting. Maybe in some sort of specific scenario he wants to customize views to his needs or choices. With Designer Rehosting you can choose to expose as much or as little functionality of Workflow as you wish.

I started with catching up on Designer Rehosting, MSDN has some great articles on that, you can find them here. Microsoft made some sample bits to get you up to speed, those can be found here. After I read the documentation (that's a lie) and grinding the code, I tried to do it myself. I must admit, I expected it to be easier. The actual hosting WF in a Winforms app is easy, but to put something of a framework together that was hard. Maybe I should have just copied all the code from the sample bits, but I hate to do that.

All the things you need to get your view in order can be found in System.ComponentModel.Design. I used the WorflowView, DesignSurface and the WorkflowDesignerLoader to get my View in order. After a little bit of yelling and screaming at my PC, the view looked like this:

winapp

The thing that got me screaming was the toolbox control, I expected that this toolbox would be in System.ComponentModel.Design, it was not. I did not find a control that showed me all the Activities from System.Workflow.Activities, so I ended up making the thing by myself. I don't know why Microsoft chose to not expose that control, but it sure would have helped me. Then again I'm now able to (for example) let the InvokeWebServiceActivity disappear from my toolbox, or show one of my own custom Activities.

So now I'm able to drag and drop my Activities to my Workflow, that's cool! This is the basics on Designer Rehosting. I can load a Workflow and show it in my app. I didn't have time to get the Tracking ready, that will be my next project and just for fun I want to be able to add some code, but that's a whole different ballgame.

To be honest I think that you should really think about if you want to use Designer Rehosting. It sounds easy and they make it look like you really want to, but you need to write a lot of plumbing code before you even have a simple app like this. I don't think there will be a lot of customers that really need Designer Rehosting, there are usually other (better and simpler) solutions for the same problem.