This sample demonstrates how to access Windows Communication Foundation (WCF) performance counters and how to create user-defined performance counters. This sample is based on the Getting Started.
The setup procedure and build instructions for this sample are located at the end of this topic.
In this sample, the client calls the four methods of the
ICalculator service. The client continues to do this until it is interrupted by the user. The service remains unchanged.
Performance counters are enabled in the diagnostics section of the Web.config file for the service, as shown in the following sample configuration.
<configuration> <system.serviceModel> <diagnostics performanceCounters="All" /> </system.serviceModel> </configuration>
This task can also be done using the Configuration Editor Tool (SvcConfigEditor.exe).
When performance counters are enabled, the entire suite of WCF performance counters is enabled for the service. The .NET Framework automatically maintains performance data at three levels:
ServiceModelOperation. Each of these levels has performance counters such as "Calls", "Calls per Second", and "Security Calls Not Authorized".
To set up, build, and run the sample
Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.
To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.
To run the sample in a single- or cross-computer configuration, follow the instructions in Running the Windows Communication Foundation Samples.
To view performance data
Start the Performance Monitor Tool by clicking Start, Run…, enter
perfmonand click OK, or from Control Panel, select Administrative Tools and double-click Performance.
You cannot add counters until the sample code is running.
Remove the performance counters that are listed by selecting them and pressing the Delete key.
Add WCF counters by right-clicking the graph pane and selecting Add Counters. In the Add Counters dialog box, select ServiceModelOperation 188.8.131.52, ServiceModelEndpoint 184.108.40.206, or ServiceModelService 220.127.116.11 in the Performance object drop down list box. Select the counters you want to view from the list.
There are no WCF performance counters for a service if there are no WCF services running on the computer.
To use the Configuration Editor to enable counters
Open an instance of the SvcConfigEditor.exe.
On the File menu, click Open and then click Config file….
Navigate to the sample application's service folder and open the Web.config file.
Click Diagnostics on the Configuration tree.
Toggle Performance Counter in the Diagnostics window to show 'All'.
Save the configuration file and exit the editor.
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.