Profiling WCF applications
Published 11 June 2013
In ANTS Performance Profiler, you can profile Windows Communication Foundation (WCF) applications. To do this it can help to think of a WCF application as a server in a server-client relationship, where a client application consumes data from the WCF application, and you collect performance data by interacting with that client.
The method you use to profile WCF applications depends on what you are using to host it.
You can profile WCF services:
- that are implemented as .NET executables (for example, WCF applications that are not hosted on a web server)
- that are hosted in IIS
- as a Windows service (that runs in the background)
Profiling WCF services as .NET executables
If your WCF application is implemented as a .NET executable, the procedure for profiling is the same as the procedure used to profile other .NET executables.
To profile a .NET executable:
- From the list of application types, click .NET executable.
- Type or browse to the Path to .NET executable that you want to profile.
You can use the dropdown list to select a recently-profiled application. - If you need to specify any command line arguments for the application, click Show startup options.
You can add arguments and change the working directory for the profiling session here. The working directory is the path where the application will start. By default, this is the directory where the executable is located. Select the required Profiling mode, Chart performance counters, Additional profiler options, and the browser to launch the application.
For more information, see Working with application settings and Setting up chart performance counters.- Click
The .NET executable starts, profiling begins, and your performance counters start to show on the timeline.
During a profiling session you can interact normally with your application and with the profiler.
Profiling WCF services hosted in IIS
The procedure for profiling WCF services running in IIS is similar to the procedure used to profile other types of web application in IIS.
To profile a WCF service hosted in IIS, perform the following steps:
Before you start, change the WCF client contract to communicate on the unused port that you select in ANTS Performance Profiler (by default, 8013).
Changing the port is necessary because otherwise the client will communicate with the copy of the server hosted in IIS, not the copy in the worker process started by ANTS Performance Profiler.
- In ANTS Performance Profiler, on the setting screen, from the list of application types, click IIS - ASP.NET.
- Set the URL for ASP.NET web application to the path to the the WCF web application on the server.
To load a list of currently-running sites from IIS into the dropdown list, click
Note that the port specified in this URL is the port where the application usually runs under IIS, which is not necessarily the same as the port where the application is to be profiled. - To set your server options, click Show server options.
Port and ASP account settings are displayed:
From the server options, choose a port. The port you profile on depends on your version of IIS. The profiler automatically detects the version of IIS you are using.
If you are using IIS 5, ANTS Performance Profiler will profile your application on its original port. This will automatically restart IIS.If you are using IIS 6 and later, you can choose to profile on the original port or on an unused port:
Select Unused port if your application does not bind to a specified port. ANTS Performance Profiler will start a new instance of your application on the specified port, avoiding a restart of IIS. The port where the application will be profiled is displayed at the bottom of the settings screen.
Select Original port if your application's code binds to a specific port. ANTS Performance Profiler will stop your application, attach to it, and restart it on the original port.
- Specify which user to run the profiling session as.
From the server options, select Manually specify ASP.NET account details and enter the User name, Password and (in IIS 6 and 7) Domain.- With IIS 5, ANTS Performance Profiler can only run as the ASPNET user. Ensure that this user has permission to read from: %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\ProfilerCore.dll and %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\X64\RedGate.ProfilerCore.dll
If your Application Host configuration file is set to protect the credentials of the ASPNET user, ANTS Performance Profiler may be unable to detect them. In this case, select Manually specify ASP.NET account details and enter the ASPNET username and password. - With IIS 6 and later, ANTS Performance Profiler profiles your web application as the Windows Local System user by default. This is appropriate for most websites. However, if your web application connects to a remote server (such as a database server), the Windows Local System user might not have appropriate permissions to make the remote connection. In this case, enter the credentials of a user who does have the required permissions. Note that the user you specify must be an administrator, and must have permission to read from %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\ProfilerCore.dll and %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\X64\RedGate.ProfilerCore.dll
- With IIS 5, ANTS Performance Profiler can only run as the ASPNET user. Ensure that this user has permission to read from: %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\ProfilerCore.dll and %ProgramFiles%\Red Gate\ANTS Performance Profiler 8\X64\RedGate.ProfilerCore.dll
- Select the required Profiling mode, Chart performance counters, Additional profiler options, and the browser to launch the application.
For more information, see Working with application settings and Setting up chart performance counters.
Note that SQL queries and incoming HTTP calls will be profiled automatically. - In the browser selection dropdown, choose the browser you want to use if you application has a web interface. Otherwise, ensure No browser is selected.
- Click
Profiling starts. If you have selected a browser but your application does not have a web interface, a browser window will launch. You can ignore this window and interact with your application normally.
Profiling WCF services as Windows services
To profile a WCF application as a Windows service, the procedure for profiling is the same as the procedure used to profile other Windows services.
To profile as a Windows service:
- From the list of application types, click Windows service.
- Select your .NET Windows Service from the drop down list.
Click to update the list of Windows services. - If you need to specify any command line arguments for the application, click Show startup options.
The Arguments box is displayed. Type any arguments you want to use here. - Select the required Profiling mode, Chart performance counters, Additional profiler options, and the browser to launch the application.
For more information, see Working with application settings and Setting up chart performance counters. - Click
If the service is not already started, ANTS Performance Profiler will start the service. If the service is already started, the profiler will restart the service.
During a profiling session you can interact normally with your service and with the profiler.
Start interacting with the client program to call the service. The service's communications with the client are included in the results.
Ending a profiling session
During a profiling session you can interact with the profiler while your application is still being profiled, and obtain results by selecting areas of the timeline; see Working with the timeline.
When you have finished interacting with your application, click the button in ANTS Performance Profiler to stop profiling.
If ANTS Performance Profiler launched a browser when you began profiling, closing the browser window will not cause profiling to stop.