Extract WF Data using Tracking
This sample demonstrates how to use workflow tracking to extract workflow variables and arguments from activities. It also shows the addition of annotations to tracking records and the extraction of data payload within custom tracking records. The sample uses the Event Tracing for Windows (ETW) tracking participant to extract data from the workflow.
Windows Workflow Foundation (WF) provides tracking to gain visibility into the execution of a workflow instance. The tracking runtime emits workflow tracking records during the execution of the workflow. Along with the workflow tracking records, data within the workflow instance can be extracted from the workflow. The following list details the types of data that can be extracted from tracking records:
Workflow variables within an activity and tracking records during activity execution.
To extract workflow variables, the variables to be extracted are specified in a profile. Variables to be extracted can only be specified with
ActivityStateQueries. The following code example demonstrates a tracking profile used to extract the workflow variable from an activity.
Activity arguments and activity state tracking records.
Arguments define the way data flows in or out of an activity. Arguments to be extracted are specified using an ActivityStateQuery.The following code example is a tracking profile that extracts the
Annotations are key/value pairs that can be added to any tracking record that is emitted.
Annotations serve as a tagging mechanism for tracking records. Annotations are added to tracking records through a tracking profile. Annotations can be added to any type of a workflow tracking query. The following code example is a tracking profile that shows how an annotation can be added to a tracking record.
Custom tracking records are emitted from user-defined activities.
Custom tracking records can carry payload data defined within this activity. Subscribing for custom tracking records in a tracking profile allows the extraction of the payload within the tracking record. The custom tracking records can be extracted with custom a TrackingQuery. The following code example is a tracking profile that extracts a custom tracking record along with its payload.
<customTrackingQuery name="QuoteLookupEvent" activityName="GetStockPrice"/>
The sample demonstrates the extraction of a variables, arguments, custom records and adding annotations using a profile specified in a Web.config. Tracking is enabled on the sample workflow service by adding an
<etwTracking> behavior element. The following code example enables tracking for the
ExtractWorkflowVariables tracking profile.
<serviceBehaviors> <behavior> <etwTracking profileName="ExtractWorkflowVariables"/> </behavior> </serviceBehaviors>
To use this sample
Using Visual Studio 2010, open the WFStockPriceApplication.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press F5.
The browser window opens and shows the directory listing for the application.
In the browser, click StockPriceService.xamlx.
The browser displays the StockPriceService page, which contains the local service WSDL address. Copy this address.
The following example shows a local service WSDL address.
Before invoking the service, start Event Viewer and ensure that the event log is listening for tracking events emitted from the workflow service.
From the Start menu, select Administrative Tools and then Event Viewer.
In the tree view in Event Viewer, navigate to Event Viewer, Applications and Services Logs, and Microsoft. Right-click Microsoft and select View and then Show Analytic and Debug Logs.
Ensure that the Show Analytic and Debug Logs option is checked.
In the tree view in Event Viewer, navigate to Event Viewer, Applications and Services Logs, Microsoft, Windows, Application Server-Applications. Right-click Analytic and select Enable Log.
Using Windows Explorer, open the WCF test client.
The WCF test client (WcfTestClient.exe) is located in the <Visual Studio 2010 installation folder>\Common7\IDE\ folder.
The default Visual Studio 2010 installation folder is C:\Program Files\Microsoft Visual Studio 10.0.
In WCF test client, select Add Service from the File menu.
Add the local service WSDL address you copied earlier in the input box.
In WCF test client, double-click
This opens the
GetStockPricemethod. The request accepts one parameter. Use the value Contoso.
Switch back to Event Viewer and navigate to Event Viewer, Applications and Services Logs, Microsoft, Windows, Application Server-Applications. Right-click Analytic and select Refresh. The workflow events are in the event ID ranges 100-199.
The events contain the annotations, variables, arguments and custom tracking records that can be viewed in the event viewer.
Cleaning up in the Event Viewer
The analytic channel in the event log can be cleaned up in the Event Viewer by doing the following.
To clean up (Optional)
Open Event Viewer.
Navigate to Event Viewer, Applications and Services Logs, Microsoft, Windows, Application Server-Applications. Right-click Analytic and select Disable Log.
Navigate to Event Viewer, Applications and Services Logs, Microsoft, Windows, Application Server-Applications. Right-click Analytic and select Clear Log.
Choose the Clear option to clear the events.
There is a known issue in the Event Viewer where it may fail to decode ETW events. You may see an error message that looks like the following.
The samples may already be installed on your computer. Check for the following (default) directory before continuing.