我正在用 C# (.NET Framework 4.5) 为 Microsoft Windows Server 2012 R2 Standard x64 (IIS 8.5) 编写一个 Windows 服务应用程序,并使用 Microsoft.Web.Administration.dll (7.0.0.0 from C:\Windows\System32\inetsrv )。
当我运行以下代码时:
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)}
有人可以给我建议吗?