Using the WCF OperationContext from a Receive activity

The WF4 Receive activity shields you from a lot of the WCF pipeline. Normally that is a good thing but there are occasions where you want to know more about the incoming WCF request. Normally you can use the WCF OperationContext.Current to get at this information but with a workflow service this doesn’t work as it is null. The reason is that the workflow executes on a different thread.   So how do you get at the OperationContext? The trick is to add a class implementing the IReceiveMessageCallback interface to the NativeActivityContext.Properties while the receive is executing and this will … Continue reading Using the WCF OperationContext from a Receive activity

Converting a C# workflow into XAML

A interesting question that came up last week was how to convert workflows defined in C# to XAML. A co worker of one of the attendees of the Essential Windows Workflow Foundation 4 course had been experiencing a lot of problems with the workflow designer and decided to create their workflows in C# instead of using the designer to generate XAML. While these workflows run just fine you do lose the visual aspect of the designer, one of the benefits of workflow in the first place. Fortunately it isn’t hard to save workflow objects, however they have been authored, into … Continue reading Converting a C# workflow into XAML

Workflows and no persist zones

There are times when a workflow can’t be persisted safely using a SqlWorkflowInstanceStore. The reason isn’t so much saving the state of  a workflow to disk, that could be done at any time, but the result when a workflow would be reloaded from disk in that state. An easy example is a workflow handling a WCF request with a Receive and SendReply activity pair. Suppose you would save the workflow state after the message had been received but before the response had been send. No problem there. Now suppose the workflow is aborted just after the response is send and … Continue reading Workflows and no persist zones

Hiding the XAMLX from a workflow service

In Windows Workflow Foundation 4 it’s easy to create a workflow and expose it as a WCF service. But one thing is that it exposes a XAMLX endpoint to each client can see the service actually implemented as a workflow service instead of a regular service. One way to hide that is to use a regular SVC file as the implementation and point that to a workflow using the WorkflowServiceHostFactory.   See the original XAMLX extension   To change this to an SVC extension we need to do a few things. First we need to use a regular workflow instead … Continue reading Hiding the XAMLX from a workflow service

More Workflow 4 Services and duplex communications

Yesterday I posted a long blog post explaining how to do duplex communications in a Workflow service. Its a long story but the most important points where that workflow services don’t support the same style duplex communication as WCF with the callback channel defined in the ServiceContract but rather something that is called durable duplex where the callback contract is independent and the client has to create a ServiceHost and act as a full-blown WCF service. Also the callback address had to be passed by the client using CallbackContextMessageProperty and the workflow service had to use a callback correlation handle … Continue reading More Workflow 4 Services and duplex communications

Workflow 4 Services and duplex communications

There are quite a a few cases where it is useful to have a duplex communications. An obvious candidate is allowing a service to notify the user interface application of the progress so the user knows what is happening. Normally, when using plain WCF, you would use a ServiceContract attribute with a CallbackContract that specified the service uses duplex communications. For example something like the following code on the server: [ServiceContract(CallbackContract = typeof(IService1Callback))] public interface IService1 { [OperationContract] string GetData(int value); }   [ServiceContract] public interface IService1Callback { [OperationContract] void Reply(string message); } along with a client like this: class … Continue reading Workflow 4 Services and duplex communications

Workflow Receive activity and message correlation

With WF4 it is quite easy to use data that is part of the request message, for example an order identifier, to route multiple WCF messages to the same workflow. It is also possible to have multiple messages that can start a new workflow. In this blog post I am going to show both these concepts in a single workflow. This workflow is going to be able to receive three different messages, AddItem, AddExpensiveItem and Submit.  Either AddItem or AddExpensiveItem can start a new workflow while Submit can only be done with an existing workflow. The final workflow looks like … Continue reading Workflow Receive activity and message correlation

Trying the WF ADO.NET Activity Pack CTP 1

Recently the workflow team at Microsoft released a first CTP to the ADO.NET Activity Pack. In this blog post I am going to take a quick look at how to get started with these activities.   First step is installing the activity pack. Download the setup MSI from and run the installer. This will install the activities in the folder C:\Program Files (x86)\Microsoft WF ADO.NET Activity Pack\CTP 1 and register them with VS2010 so they automatically appear in the toolbox. Note that the main assembly containing the activities is called Microsoft.Data.Activities.dll. If we start VS2010 and create a new … Continue reading Trying the WF ADO.NET Activity Pack CTP 1

Workflow 4 and soap faults

Image by ponChiang via Flickr Note: This blog post is written using the .NET framework 4.0 RC 1   Using the ReceiveAndSendReply activity template and the WorkflowServiceHost it is easy to create a workflow service. Other applications can communicate with the workflow just as if it is a regular WCF service, they never need to know the difference. Most of the configuration is quite straightforward. Select the Receive activity and configure it and do the same with the SendReply activity. Most the settings normally done using a ServiceContract or an OperationContract are there. But what about faults? Turns out there … Continue reading Workflow 4 and soap faults