I'm writing a windows service application in C# (.NET Framework 4.5) for Microsoft Windows Server 2012 R2 Standard x64 (IIS 8.5) and using Microsoft.Web.Administration.dll (7.0.0.0 from C:\Windows\System32\inetsrv).
When I run the following code:
using(var srvmngr = new Microsoft.Web.Administration.ServerManager())
{
foreach(var pl in srvmngr.ApplicationPools)
{
foreach (var w3wp in pl.WorkerProcesses)
{
foreach (var request in w3wp.GetRequests(0))
{
var success = true;
}
}
}
}
The Service starts with administrator privileges and "GetRequests(0)" method raises the following exception:
System.NotImplementedException - {"The method or operation is not implemented."}
StackTrace:
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()
at Microsoft.Web.Administration.ConfigurationMethodInstance.Execute()
at Microsoft.Web.Administration.WorkerProcess.GetRequests(Int32 timeElapsedFilter)
Got the same exception in PowerShell using the following code:
PS > [System.Reflection.Assembly]::LoadFrom("C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )
PS > $sm = new-object Microsoft.Web.Administration.ServerManager
PS > $sm.workerprocesses | foreach-object {$_.GetRequests(0)}
Can someone advice me?
I finally have solved my problem.
Follow the steps below to complete this problem: Add Roles and Features Wizard -> Server Roles -> Web Server (IIS) -> Web Server -> Health and Diagnostics -> Request Monitor