Tracking Using a Text File
This sample demonstrates how to extend tracking in Windows Workflow Foundation (WF) by creating a custom tracking participant. Tracking participants are .NET Framework classes that receive tracking records from the runtime as they are emitted. You can create a tracking participant to transport the tracking events to whichever destination is required for your scenario. For example, ETW (Event Tracing for Windows) Tracking Participant is provided as part of the .NET Framework. The tracking participant in this sample writes the records in XML format to a text file.
To optimize the usefulness and robustness of your tracking participant, some additional steps must be completed to properly wire the tracking participant to the runtime. The following table describes the classes used in this sample to create a tracking participant that complies with best practices.
|A BehaviorExtensionElement is used to define the configuration section used to configure the text file tracking participant. This allows users to specify the destination of the log file using standard .NET Framework configuration files.|
|Behaviors in WCF allow users to inject extensions into the runtime. This behavior adds the tracking participant to the service when the service starts.|
|The tracking participant that receives tracking participants at runtime and stores them to a log file as XML.|
One more step is required to make use of the behavior extension element previously described using .NET Framework configuration files. The following configuration must be placed in configuration files where the extension is to be used.
<system.serviceModel> <extensions> <behaviorExtensions> <add name="textFileTracking" type="Microsoft.Samples.TextFileTracking.TextFileTrackingExtensionElement, WFStockPriceApplication, Version=184.108.40.206, Culture=neutral, PublicKeyToken=null" /> </behaviorExtensions> </extensions> … </system.serviceModel>
See the Web.config file in the sample for a complete example usage of behavior extension elements configuration.
The GetStockPrices.cs file demonstrates how to create custom tracking records from within a CodeActivity. Look for this record when running the sample.
Using Visual Studio 2010, open the WFStockPriceApplication.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press CTRL+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.
An example of the local service wsdl address is http://localhost:53797/StockPriceService.xamlx?wsdl.
Using File Explorer, go to your Visual Studio 2010 folder (the default installation folder is %SystemDrive%\Program Files\Microsoft Visual Studio 10.0). Then locate the Common7\IDE\ subfolder.
Double-click the WcfTestClient.exe file to launch the WCF Test Client.
In the WCF Test Client, select Add Service… from the File menu.
Paste the URL you just copied into the text box.
Click OK to close the dialog.
Test the service using the WCF Test Client.
In the WCF Test Client, double-click GetStockPrice() under the IStockPriceService node.
The GetStockPrice() method appears in the right pane, with one parameter.
Type in Contoso as the value for the parameter.
See the tracked events in the log file located in your application data directory at %APPDATA%\trackingRecords.log.
The %APPDATA% is an environment variable that resolves to %SystemDrive%\Users\<username>\AppData\Roaming in Windows Vista, Windows Server 2008, or Windows Server 2008.
The samples may already be installed on your computer. 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.