This sample demonstrates the use and configuration of promoted properties in the SQL workflow instance store. The SQL workflow instance store is a SQL-based implementation of an instance store. It allows an instance to save its state and load its state to and from a SQL Server or SQL Server Express database. The store extensibility feature allows the user to define properties that are stored in the instance store. These properties are displayed in a promoted properties view that allows the user to query for them.
This sample consists of a workflow that implements a counting service. Once the service's start method is invoked, the service counts from 0 to 29. The counter is incremented once every 2 seconds. After each count, the workflow persists. The current counter value is stored in the instance store as a promoted property.
The Counting Workflow is self-hosted by a Workflow Service Host. The program's
Main method performs the following actions:
Creates an instance of the Workflow Service Host that hosts the Counting Workflow and defines the endpoints under which the Counting Workflow can be reached.
Defines a SQL workflow instance store behavior, which is used to configure the SQL workflow instance store. The store is instructed to treat
CountStatusas a promoted property.
Creates a client that calls the start method of the counting workflow.
Once the program is started, the counter automatically starts counting. Note that it might take a few seconds to load the instance and configure the SQL workflow instance store.
To promote the counter value as a custom property, the following steps must be taken:
CounterStatusdefines an instance extension of type PersistenceParticipant, which is used by activities to supply the state variables.
Countis defined as a write-only value. When a workflow instance comes to a persistence point, the instance extension saves the
Countproperty into the persistence data collection.
When creating the instance store, a new property,
CountStatus, is defined through the
SaveCounteractivity assigns the current counter value to the
Create the instance store database.
Open a Visual Studio 2010 command prompt.
Navigate to the sample directory (\WF\Basic\Persistence\SqlStoreExtensibility\CS) and run CreateInstanceStore.cmd in the Visual Studio 2010 command prompt.
The CreateInstanceStore.cmd script attempts to create the database on the default instance of SQL Server 2008 Express. If you want to install the database on a different instance, modify the script to do so.
Open Visual Studio 2010 and load the SqlStoreExtensibility.sln solution and build it by pressing CTRL+SHIFT+B.
If you installed the database on a non-default instance of SQL Server, update the connection string in the code prior to building the solution.
Run the sample with administrator privileges by navigating to the project’s bin directory (\WF\Basic\Persistence\SqlStoreExtensibility\bin\Debug) in File Explorer, right-clicking SqlStoreExtensibility.exe and selecting Run as Administrator.
Use SQL Server Management Studio to view the contents of the instance table by selecting Databases, InstanceStore, and then System.ServiceModel.Activities.DurableInstancing.InstanceTable in the Object Explorer, right-click System.ServiceModel.Activities.DurableInstancing.InstanceTable and select Select Top 1000 Rows. For more information about SQL Server Management Studio, see Introducing SQL Server Management Studio
Observe the workflow instances listed.
In a Visual Studio 2010 command prompt, run the QueryInstanceStore.cmd script located in the sample directory (\WF\Basic\Persistence\SqlStoreExtensibility).
Observe the counter value displayed under CountStatus.
Run the script a few times to see the CountStats value change.
Press ENTER to terminate the workflow application.
- Remove the instance store database by running the RemoveInstanceStore.cmd script located in the sample directory (\WF\Basic\Persistence\SqlStoreExtensibility).
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.