Retrieving Tracked Variables from the Windows Server AppFabric Monitoring Store

This sample shows how to use the Entity Framework to retrieve and deserialize tracked Workflow variables from the AppFabric monitoring database. You will learn about some of the public views exposed by the monitoring database that make this possible. This sample will work with any application. We recommend the Common Windows Server AppFabric Sample Application, which was created for use with AppFabric samples. To find this application, navigate to the <samples>\SampleApplication\OrderApplication folder, where <samples> is the path under which you have installed the AppFabric samples.

Note

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples.

Prerequisites

  • A Windows Server AppFabric Installation with monitoring configured.

  • At least one WCF or WF service hosted in the AppFabric.

Note

This sample is more illustrative of the monitoring capabilities if the service is configured to track a variable that is of a complex type.

If you are deserializing tracked variables from a custom assembly, be sure to add the assembly (e.g. the AppFabric Sample Application) as a reference to this project so that it can properly deserialize those objects.

Sample Files

This sample comes with the following files:

  • VS 2010 Solution structure and supporting code files

  • TrackedWFVariable.cs

  • Program.cs

Setting Up and Running This Sample

  1. Make sure that variables have been tracked and stored in the monitoring database. You can do this by inspecting the WFEventProperties view and ensuring that there are rows present.

  2. Open the Visual Studio Solution that is included with this sample.

    Important

    Make sure you are running under an account that has read access to the AppFabric monitoring database.

  3. Edit the Database value in Program.cs so that it points to your desired database.

  4. Edit the value that is passed to the AppFabricMonitoringEntities constructor in Program.cs. By default, it points to a SQL Express instance. A Standard SQL instance name has been included at the top of the file for simplicity.

  5. Build and run the sample by pressing F5.

Understanding This Sample

Program.cs uses the Entity Framework to query the database for the most recent Workflow events. The TrackedWFVariable class uses the Entity Framework data context to connect to retrieve any WFEventProperty rows that are related to the recent events. The properties are then deserialized into their original .NET types. This process is different depending on the type of the object to deserialize.

The following types are stored as a simple string representation in the Value column of the WFEventProperties view:

  • System.String

  • System.Char

  • System.Boolean

  • System.Int32

  • System.Int16

  • System.Int64

  • System.UInt32

  • System.UInt16

  • System.UInt64

  • System.Single

  • System.Double

  • System.Guid

  • System.DateTimeOffset

  • System.DateTime

These types can be deserialized by calling the static Parse methods that these types define, passing in the string values as a parameter. All other types have their value stored in the ValueBlob column of the WFEventProperties view and must be deserialized using the System.Runtime.Serialization.NetDataContractSerializer. This requires that the assembly that declares that type to deserialize must be loaded. The objects are stored in the database in this way so that the simpler types listed above can be queried easily by SQL clients.

Removing This Sample

This sample does not leave any artifacts behind. You can delete the sample files if you wish