Tips, tricks and all the info about Microsoft Visual Studio 2008

Windows Workflow Enhancements in Visual Studio 2008

, posted: 17-Mar-2008 09:00

One of the enhancements to Visual Studio 2008 and the .Net 3.5 platform that I was really interested in was Workflow Services. Having spent much time developing my own infrastructure for Windows Workflow (WF) to handle external events using External Data Exchange (EDE) and Local Communications services (LCS) I was keen to see what approach Microsoft took to making the problem less painful. 

The LCS/EDE samples are sparse and the approaches taken by different authors are quite divergent. The Microsoft documentation also glosses over some of the key details which makes it difficult to get your first real world application working reliably. 

In addition, the decision to make Windows Workflow a “meta” workflow (a reasonable approach for a vendor of Workflow systems) makes what you might expect to be mundane tasks surprisingly complex.
With Microsoft’s recent software releases, the tooling (Visual Studio 2008) and infrastructure (.Net 3.5) work together to solve the problems of a visual design environment, hosting the workflow, routing responses to the correct workflow instance, and routing responses to the correct  activity instance in the specified workflow instance.

Visual Studio 2008 supports the .Net 3.5 Workflow extensions via two additional project templates in the Windows Communication Framework (WCF) section. The “Sequential Workflow Service Library” and “State Machine Workflow Service Library” templates generate a basic Workflow, an interface specification and the configuration files required to host the workflow as a WCF service.

The Conversations sample provides an introduction to the use of Workflow Services, the management of context,  and the use of netTcpContextBinding , which along with basicHttpContextBinding  are the two new context aware bindings.

The DinnerNow sample and associated source illustrate how all of the .Net 3.5 (with additional material covering Windows Mobile 6, IIS7 etc.) technologies can be used together to provide a complete “end to end” solution for a fictional restaurant meal delivery service.

One of my main uses of WF has been the management of aggregation using combinations of sequential and state machine workflows. I usually have sequential workflows for processes where the workflow is in control, and state machine workflows for where a human is in control.

The Visual Studio 2008 support for Workflow Services workflow design is via the SendActivity and the ReceiveActivity the in toolbox. When using the SendActivity and ReceiveActivity features of Visual Studio 2008 I start with a pre-baked implementation of the interfaces I wish to call and/or implement rather than building them on the fly.

I use both the IDesign WCF Coding Standards and the WCF Contract Design Guidelines written by Simon Evans from Conchango for guidance. These are just two authors (of many) whose guidance I have found to be well considered and reasonable.

The ReceiveActivity listens for specific method invocations and handles the associated logic in a workflow. It can be a container for other activities and hold them as part of its execution flow.

For example in the Dinner Now sample the order process is initiated by the following request:

void StartRestaurantOrder(RestaurantOrder order, System.Collections.Generic.Dictionary context);

As calling this method starts the process of handling an order the ReceiveActivity CanCreateInstance property should be set to true so a new workflow instance is created.

It is also important the correct context information is flowed from one workflow activity to another. In the Conversations sample SupplierWorkflow the context passed to the SubmitOrder activity in the request (A ReceiveActivity) is assigned to the context of the Order Details (A SendActivity) for the response.

The ReceiveActivity also allows you to specify what WCF channel to be used. This is a sample from the Customer console workflow application which is part of the Conversations sample.


The Conversations sample has three hardwired Shippers which is most probably not terribly representative of aggregation in the real world. Where the number of service providers is not known in advance a Replicator activity could be used to spawn multiple (optionally “concurrently” executing) instances of a custom activity.

The management of context is not quite seamless but is largely handled “automagically” by the runtime. But on the first request the developer does need to implement the initial context exchange.  In the Customer workflow of the Conversations sample the context is set in the “BeforeSend” processing of the SendActivity:

private void PrepareOrder(object sender, SendActivityEventArgs e)
            this.order.Amount = 1000;
            this.order.OrderId = 1234;
            this.contextToSend = this.ReceiveOrderDetails.Context;

The management of context in a replicator is critical and associating the SendActivity with the correct OwnerActivity (in the case of the SupplierWorkflow in the Conversations sample the hosting parallel activity) and setting the CustomAddress property to target different service instances is necessary for correct functioning of the workflow.

For long running activities in workflows such as database lookups and remote calls (i.e. > 0.1 sec) it is most probably worth implementing the “send, save state, listen response” pattern as described in this article by Paul Andrew.

The two available context aware bindings posed a major problem for me as I often use Microsoft Message Queue (MSMQ) as the bearer for WCF. I use MSMQ to increase the resilience and scalability of my applications by providing an elastic buffer between services to ensure they don’t choke on traffic spikes. It also makes my applications truly disconnected as they can go in and out of service with no impact on each other.

MSMQ and workflow services do not integrate nicely (really not at all) which has caused me much pain, though there are some third party options available. I also looked at developing my own custom channel which I found would be a non trivial exercise. As a result of this I tend to “mix n match” Workflow Services and the LCS/EDE approach in my solutions

In my opinion, the logical evolution of the tight integration of WF and WCF via Workflow Service appears to be the recently announced Oslo initiative which will provide the tooling and infrastructure for model driven design of distributed applications.
Download Visual Studio 2008 90 day trial
For detailed information and to request a free 90-day trial DVD of Visual Studio 2008 Team Suite to be sent out to you, go to the Microsoft Visual Studio webpage.

About the Author
This year will be Bryn’s 20th year in the industry. He has been working with Microsoft products since Windows 286 was hot. After a couple of years working for Microsoft Consulting Services in Auckland, he now works for Clarus a Christchurch based IT Consulting and contracting company. Bryn is a Certified Scrum Master and is involved with the Christchurch .Net development community through his work doing the logistics for the local meetings. Current projects range from process improvement, remediation, WindowsMobile development, through to highly scalable .Net 3.5 Windows Workflow and Windows Communication Framework architecture work.

Other related posts:
The Visual Studio 2008 blog is back
Visual Studio 2008 JavaScript Debugging
A completely non-comprehensive introduction to Visual Studio 2008

Comment by nzsnowman, on 17-Mar-2008 22:24

Nice one. Yes, there is definitely a deficiency with WF and MSMQ instance routing and management in the current framework, which I feel is important enough to correct via a service pack, rather than to wait until 'Oslo' materialises though. Considering that BizTalk vNext will also have to solve this problem as it will switch to using the WF FW rather than native 'orchestrations', I am guessing that the issue has probably already been solved by that team now. Share the love guys :)

Comment by Leo Van Messi, on 19-Sep-2008 21:01

Thank you!, sir. This is advantage for me.

Comment by ayman, on 24-Apr-2009 05:16

hi am tunisian student. please i need to know how to change a document state in document library using sequential workflow thanks

About the Visual Studio 2008 Blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce over 250 new features in the 2008 release.

This sponsored blog will bring Visual Studio 2008 tips and tricks from well known developers in the Australian and New Zealand tech community directly to you.

Make sure you bookmark this blog or subscribe to our RSS feed.

Other blog posts

The New Zealand ALM Conference...
Writing your own Html Helpers ...
Automating Visual Studio 2008...
Windows Azure Table Storage - ...
Windows Azure Table Storage - ...
XML and XSLT in Visual Studio ...
Introduction to New SQL Server...
Using the Visual Studio 2008 P...
Getting started with Windows A...
Why consider sitting for an MC...

Some recent comments

Praveen M on Visual Studio 2008 support for building SilverLigh: I installed SILVERLIGHT TOOLS for VS2008 at my work. I am able to do silverlight...

zefo on Unit testing with Visual Studio 2008: Just minor recommendation: better use *.png for the screenshots. Jpeg is more su...

gil ziny on Unit testing with Visual Studio 2008: When I associate the unit test with TFS testing policy, if fails during check-in...

lynette on Visual Studio 2008 JavaScript Debugging: i have enable in IE the ability to debug scripts. if i go to my section in my c...

Junkie on Why consider sitting for an MCTS or MCP Certificat: The way you presented the case for certification has been completely different f...

Brian Link on Unit testing with Visual Studio 2008: You seem to be incorrect in one of your opening remarks - it seems that web.conf...

Dipanwaya on Unit testing .Net Compact Framework applications w: Steps Behind the Test in the VS 2008? How to test a module in the VS 2008 Envir...

Ricardo on Visual Studio 2008 support for building SilverLigh: Yes! Found the solution myself :) Reset the environment of Visual Web Developer...

Ricardo on Visual Studio 2008 support for building SilverLigh: Have the same problem after installing Visual Web Developer 2008 SP1 and Silverl...

kjward on Automating Visual Studio 2008: thanks lots for all the great info. i'm sure the answer to my question is in th...


The Visual Studio 2008 blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio 2008 and are not influenced or filtered by Microsoft NZ in any way.