我正在使用C#(.NET Framework 4.5)编写一个Windows服务应用程序,运行在Microsoft Windows Server 2012 R2 Standard x64(IIS 8.5)上,并且使用Microsoft.Web.Administration.dll(从C:\ Windows \ System32 \ inetsrv中的7.0.0.0版本)。
当我运行以下代码时:
当我运行以下代码时:
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;
}
}
}
}
此服务以管理员权限启动,调用“GetRequests(0)”方法会引发以下异常:
System.NotImplementedException - {"The method or operation is not implemented."}
堆栈跟踪:
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()
at Microsoft.Web.Administration.ConfigurationMethodInstance.Execute()
at Microsoft.Web.Administration.WorkerProcess.GetRequests(Int32 timeElapsedFilter)
在 PowerShell 中使用以下代码时,出现了相同的异常:
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)}
有人能给我建议吗?
%systemroot%\system32\inetsrv\appcmd list requests
- Andrii Motrych