Durable Task Framework – Complex Types as Task Input Parameters

In my last post, Using Unity With The Durable Task Framework, I mentioned that I had originally overlooked the fact that the data passed to and from your TaskActivity objects in an orchestration are serialized and sent over the wire. If you’re using simple types then this isn’t a problem, but usually we want to be able to pass in something with a little more information.

The Durable Task Framework uses JSON.Net to perform the serialization and looking at the documentation there, we can see that there are a few options for making our complex types work with the framework. I chose the simple approach of using the System.Runtime.Serialization.DataContractAttribute and System.Runtime.Serialization.DataMemberAttribute attributes to mark my data classes as serializable.

It’s important to keep your objects to the minimum size required. The Azure Service Bus supports messages with a greater size than Windows Azure Queues, but there’s still a 256Kb limit (Capacity and Quotas sub-heading).

namespace UnityDurableTaskFramework
    using System.Runtime.Serialization;

    public class Transaction
        public decimal Amount { get; set; }

        public string SourceBankAccount { get; set; }

        public string TargetBankAccount { get; set; }

And that’s all there is to it! If you download the sample for my last blog post, you’ll see this in action.

Note: To make this work, you’ll need an Azure subscription and a service bus connection string. Edit the app.config in the project to set your subscription connection string. At present, there isn’t any way to emulate the service bus locally.

Also make sure you have the NuGet package manager installed. The source archive doesn’t contain all the dependencies to save on storage space, but when you first build the project they should be downloaded automatically.

Posted in .Net 4.5, Azure, Durable Task Framework, Service Bus, Source Code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: