【问题标题】:Which windows services are required to start System.Net.HttpListener on a XP machine?在 XP 机器上启动 System.Net.HttpListener 需要哪些 Windows 服务?
【发布时间】:2013-01-10 08:09:24
【问题描述】:

在我们的一些客户 WinXP SP3 机器上,几乎每天都会发生奇怪的行为。

我们安装了一个在启动时执行以下代码的 Windows 服务:

if( !HttpListener.IsSupported )
{
    throw new Exception( string.Format( "HttpListener is not supported on {0}.", Environment.OSVersion ) );
}

_httpListener = new HttpListener();
_httpListener.Prefixes.Add( "http://localhost:20001/" );

_thread = new Thread( new ThreadStart( StartListening ) );
_thread.Start();

现在有时当 Windows 启动时,代码会抛出“不支持”异常。停止并再次启动服务后,HttpListener 工作!

我的 Windows 服务是否需要任何服务依赖项?

【问题讨论】:

  • 我认为您的问题已经得到解答:stackoverflow.com/questions/10026387/…
  • 看到了,但奇怪的是,httplistener 在停止和启动服务后正在工作。它只是看起来像其他一些依赖 http 服务有时比我的服务启动慢..
  • 好的,我明白了。也许您的 http.sys 驱动程序有问题?我也去网上查一下,我也想知道答案。也许你应该看看这里:codeproject.com/Articles/437733/… 并问这些人这个问题,他们可能知道更多。

标签: .net windows-services dependencies httplistener


【解决方案1】:

找到了解决办法!

在 ServiceInstaller 构造函数中只需添加以下行:

serviceInstaller.ServicesDependedOn = new string[] { "HTTP" };

这使得你自己的 Service 依赖于 Windows HTTP Service,并且在 HTTP Servive 成功启动后才启动。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多