Sample Title

Side-by-Side Hosting of Multiple
Versions of a Workflow Service without Writing Additional Code

 

Overview

The WorkflowIdentity stamped on each WorkflowService instance that is created by a host allows the same WorkflowServiceHost to support multiple versions of a given definition of a Workflow. This Sample demonstrates how side-by-side versioning of Workflow Services could be enabled without writing additional code in WF 4.5.  
 

Keywords

Workflow Services, Side-by-Side, Versioning, WorkflowIdentity

 

Table of Contents

 

Objectives

This sample aims to illustrate how side-by-side versioning to Workflow Services could be enabled declaratively and without writing additional code in WF 4.5.

Pre-requisites

Familiarity with:
 

Software Requirements

 

Build Number Used For Sample Code


Description

 
1. Introduction
Microsoft has introduced the concept of WorkflowIdentity in Windows Workflow Foundation 4.5. This identity is stamped on each WorkflowService instance that is created by a host and allows the same WorkflowServiceHost to support multiple versions of a given definition of a Workflow. A previously published sample, illustrates how side-by-side versioning of Workflow Services could be enabled using the WorkflowServiceHost.SupportedVersions Property and the APIs added in WF 4.5. This sample demonstrates how side-by-side versioning could be enabled declaratively and without writing additional code. 
 
2. Scenario
Contoso Loans offers 1-year loans to its customers. Through using the GetAQuote service of Contoso Loans, customers can enter their Name and then get the current interest Rate. Later on, they can come back, enter their Name and the Amount of the loan that they need; and the service will tell them the amount that they will need to pay back in a year. Since interest rates can change overnight, Contoso Loans should be able to update the GetAQuote service with new interest rates. Nevertheless, Contoso wants the customers that have received a quote based on the previous interest rate but have not determined the amount of the loan, to be able to use the previous version of the service which was based on the previous rate. As a result, Contoso Loans requires two versions of the GetAQuote Service to run side-by-side. One version, with the previous interest rate for customers who are in the middle of using the service and have received the interest rate but have not determined the amount; and another updated version, for customers that
will be using the service from the current time moving forward.
Please note that this is a contrived example for the purpose of showing how side-by-side versions of Workflow Services could be enabled. In real world scenarios, the updated version can include significant changes to the business process.
This sample includes the following steps: 
3. Implementing Version 1 of The Service
As we mentioned in the scenario:
“Contoso Loans offers 1-year loans to its customers. Through using
the GetAQuote service of Contoso Loans, customers can enter their Name and then get the current interest Rate. Later on, they can come back, enter their Name and the Amount of the loan that they need; and the service will tell them the amount that they will need to pay back in a year.”
In order to implement this scenario we will need two ReceiveAndSendReply activities that correlate on the Name of the user.
In order to see the details of the Workflow configuration:
In this Workflow, the second Receive activity correlates with the first one on the Name of the user. In order to verify that:

This sample requires that you set up a persistence store for your Workflow. In summary, you would need to create a database to persist workflow instances. To clean up the persistence database to have a fresh database, run the scripts in %WINDIR%\Microsoft.NET\Framework\v4.xxx\SQL\EN in the following order.
  1. SqlWorkflowInstanceStoreSchema.sql
  2. SqlWorkflowInstanceStoreLogic.sql
If you need further information about setting up a persistence store, you can refer to MSDN documentation (e.g. How to:Enable SQL Persistence for Workflows and Workflow Services ).
Please note that before running the code you would need to replace the value of the connectionString (in the Web.config file) with the Connection String of the database that you are using for persistence. In other words, you would need to update the following line of the Web.config file.
XML
Edit|Remove
<sqlWorkflowInstanceStore connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MySQLPersistenceStore;Integrated Security=True" />
 You can find the Connection String of the database that you are using for persistence by following these steps:

 

 
4. Deploying Version 1 of The Service 
Now you can deploy the GetAQuote service.
 
 
The GetAQuote service is up and running. Now customers can connect to the service and request a Rate.

While this customer is considering their options; the interest rate may change overnight. While Constoso wants this particular customer to be able to borrow money based on the 2% interest rate that they have received, new customers should be treated based on the new interest rate which is 10%. Therefore, Contoso will need a new version of the service (Version 2) running side-by-side the old version (Version 1).


5. Deploying Version 1 and Version 2 Side-by-Side without Writing Additional Code

Before actually enabling Version 2, let’s take a look at the WorkflowIdentitly of Service1.xamlx. Click outside of the root activity in the designer to select the Workflow Service, and choose Properties Window from the View menu.

 
 

You can see that the “DefinitionIdentity” has been set as WorkflowIdentity  (selected from the drop-down list), with Name as “GetAQuote” and Version as “1.0.0.0”.  Package is optional and in this example is null.

In order to enable support for Version 2 of the service, here are the steps that you would need to take:

At this point, the Solution Explorer will look like the following:

 

 
 

  

Summary

This sample illustrated how two different versions of a Workflow Service could be hosted side-by-side without writing additional code in WF 4.5.