Cool! Copy as image in workflow foundation designer

Hey, I build slides a lot, so I like this cool feature in workflow foundation 4 designer (using Visual Studio 2010 Beta 2): copy as image.

If you need to copy a workflow (or part thereof this only works for the whole workflow, a pity, because you will want copy parts of your orchestration to a document, a whole orchestration will be too big … please Microsoft, fix this!), you can now right-click on any activity in your workflow, select copy as image and paste it directly into word, powerpoint, etc… I like it!

Workflow 4 parallel and compensation activities

So I’m looking into workflow foundation 4 (using Visual Studio 2010 Beta 2). Let’s look at the parallel activity included within. The parallel activity will schedule all of its child activities asynchronously and then wait until all children have completed or the CompletionCondition evaluates to True.

Let’s do a little experiment: Start Visual Studio and create a new workflow console application.

Drag a Sequence activity to the designer. In it add a WriteLine activity and a Parallel activity.

Drag a sequence activity inside the parallel activity. It will automatically split up to allow other branches:


Rename this sequence to left, then add a WriteLine activity, a Delay and another WriteLine activity.

Repeat this for the right branch, calling it Right. Now we only need to add two variables to time the delays. Select the Start sequence, and on the bottom of the designer click on the variables button. This will open the variables window:


In here define two variables leftDelay and rightDelay and make them of type TimeSpan using the dropdown combobox and select “Browse for Types…”. This should open the “Browse and Select a .NET Type” dialog. One of the new things I like about this window is that you can search for a type:


Finally we should end up with this:


Run and you should get this:


As you can see the parallel activity will now execute both left and right branches. But what if you want one of the branches to stop because another branch has done all that is needed? For that we can use the Parallel’s activity CompletionCondition. When one of the branches of the parallel activity completes, the parallel activity will check its CompletionCondition. If set to false, it will allow other braches to continue. Otherwise it will cancel the other, still running, branches.

So let’s test this. Click on the parallel activity and add a new boolean variable called stopProcessing (I’ve renamed the parallel activity Race, so that’s set as the stopProcessing variable’s scope):


Now set the parallel activity CompletionCondition to this variable by clicking the activity and using the property window:


Next add to each branch an assignment activity after the last writeline to set the stopProcessing to true:


Run: you should see one branch complete while the other never does:


And what about doing something when you get cancelled?

To do this we need to use a CancellationScope. A CancellationScope allows you to define what needs to be done when a branch gets cancelled, for example in a parallel activity because another branch completed with the CompletionCondition set to True.

Let’s try this. Inside the parallel activity drag a CancellationScope. Then drag the left branch in it. Repeat with a new CancellationScope for the right branch. Drag a WriteLine activity into each CancellationScope’s CancellationHandler. For example the left side should write “Left was cancelled” in the CancellationHandler:


Run again: You should now see one side complete, and the other being cancelled:


WARNING: Although you might think it is a good idea to schedule as much work as possible in parallel, this will not make your orchestration faster. WF will still schedule all activities on the same thread, so if your activities never go idle, it will take the same amount of time as if you’re using a sequence. Only if each branch in the parallel activity needs to wait on some response will using the parallel activity make a difference.

Adding Error Handling to content based routing with WCF

Yesterday I blogged about content based routing with WCF. Today I want to talk about error handling. What if you route to a service that is not available. WCF allows you to define backup services using a backup list.

So let’s do this: start by building a compatible backup service. In this case I will be using named pipes because this is a very reliable transport:

static Uri ServiceUri = new Uri("net.pipe://localhost/BackupProductService");

static void Main(string[] args)
  using (ServiceHost host = new ServiceHost(typeof(BackupProductsService), ServiceUri))

    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("Backup product service is running");


Now let’s create the backup list in the routing service’s configuration:


    <backupList name="backup">
      <add endpointName="backup" />


This adds a backup endpoint called “backup” which we of course also need to add the the client endpoints:

  <endpoint address="net.tcp://localhost:8010/ProductService1"
            binding="netTcpBinding" contract="*" name="toys" />
  <endpoint address="net.tcp://localhost:8011/ProductService2"
            binding="netTcpBinding" contract="*" name="beverages" />
  <endpoint address="net.pipe://localhost/BackupProductService"
            binding="netNamedPipeBinding" contract="*" name="backup" />


Finally we add the backup list to the filterTable:

  <filterTable name="productRouting">
     <add filterName="filterToys" endpointName="toys" backupList="backup" />
     <add filterName="noToys" endpointName="beverages" backupList="backup" />


If we now run the sample, but without the toys or beverages service, routing will automatically divert to the backup service.

Visual Studio 2010 Beta 2 available today!

I’m downloading it as we speak. So please wait until I’ve done :) Oh, for the first couple of days the download is only available through MSDN subscriber download, but then MS will make it public for everyone.

Today Microsoft announced a new (albeit beta 2) release of their flagship developer software, Visual Studio 2010. I’m curious if Sharepoint development will be available now because we’re building our new Sharepoint 2010 course and I think this would be nice to have (I’ll check it out after downloading completes, look for details here). I’ll also be looking at improvement in the Workflow Foundation 4 designer, because some things didn’t work yet with the designer (but in code it did). Of course I’m loving .NET framework 4 with its WCF improvements. I’ve been looking over them and I’m impressed. Especially with the integration of the REST starter toolkit, because I’m sure REST will become more and more important for Web service development, thinking about Silverlight for example.

And for MSDN subscribers we will get:

Free develop hours with Azure
Full access to Team Foundation Server 2010
40 hours of e-Learning

Also the official date of the launch of Visual Studio has been released: 22 march 2010. So what’s with the 22 of the month (on 22 October MS is releasing Windows 7 to the public)? :)

Generate sequence diagrams with Visual studio 2010

Cool! I’ve just discovered this new feature in Visual Studio 2010 (Beta 2) where you can generate a sequence diagram from your code. This should take the hard bit out of generating documentation from your code :)

Here’s a screen shot:


The only thing you need to to is to point to the method you want to see a sequence diagram for, right-click and choose Generate Sequence Diagram…


Then Visual Studio will ask you how deep you want to go, which classes/methods to include in the sequence diagram:


And then you can start making changes to the diagram:




Installing VS2010 Beta 2

So I’ve installed VS2010 today. Installation went quite well but you might want to uninstall the Silverlight 3 SDK because that gave an issue on my machine.

The VS logo has changed colors:


Usual license stuff…


5.6 Gb on disk required…


And there we go… This took about half an hour on my machine. Please note that I first expanded the .iso to a directory. Doing this on an external disk might speed things up…


Sharepoint developers: look at this!


And for the Silverlight people, yes, we can now do drag&drop databinding using the data sources window:


who is going to teched in Berlin?

I am looking forward going to TechEd in Berlin this year. Not only because of TechEd, but also because of the celebration of the fall of the Berlin Wall.

If you’re also going, I hope to see you there! U2U, the company I work for, will give a free TechEd ticket to the first two bookers of a new training.

For more information, visit So double fun!

Problem running the WCF 4 DiscoveryProxy sample

Today I was playing around with managed WS-discovery with WCF 4. To try a couple of things I used the WCF sample DiscoveryProxy.

However running the sample gave me this error:

{"A TCP error (10013: An attempt was made to access a socket in a way forbidden by its access permissions) occurred while listening on IP Endpoint="}

The solution is simple: The probing endpoint address was using a socket used by another application. So to make the sample work I changed the port number in the endpoint:

Uri probeEndpointAddress = new Uri("net.tcp://localhost:8020/Probe");

That fixed the problem. Don’t forget to update the client as well, because it also uses this endpoint.

Strange but true: using a keyword as a variable

Can you use a keyword as an argument, or any other kind of local variable? Why would you want to do that? That aside: how?

Easy! Just use the @ in front of any keyword and you can now use it as a variable. For example:

class Program


  static void UsingKeywordArg(string @string)





  static void Main(string[] args)


    UsingKeywordArg("Hello world");




I found this while digging through some generated code from workflow foundation 4. Cool!