1

我目前正在开发 Windows 服务以在后台下载一些电子邮件。为了便于测试,该服务的核心也可以在独立的应用程序中运行。下载邮件(服务和独立)时没有问题,但在运行服务时我无法获得 WebRequest(一切都在独立应用程序中找到)。我知道,Windows 服务受本地系统帐户的限制 - 但是有没有办法使用 (Http-)WebRequest 而无需手动更改服务用户。

在此先感谢,伯特

4

1 回答 1

1

Did you try disabling proxy ?

I had the same issue and setting proxy to null fixed the Timeouts.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Proxy = null; // bypass autodetect proxy

When you run as standalone application, your account proxy settings will be used. When runned as Service, Local Service Account is used and default proxy settings are used.

You can also try to add a breakpoint and lookup the proxy field with your debugger. This will gives you a better view of the "running Service context"

System.Diagnostics.Debugger.Break();
于 2012-08-27T16:00:20.557 回答