HttpWebResponse: Windows服务vs.控制台应用程序

本文关键字:控制台 应用程序 vs 服务 Windows HttpWebResponse | 更新日期: 2023-09-27 18:10:51

我有一个问题,我已经两天没能解决了。

在控制台应用程序中,这段代码工作得很好:

url="http://www.reuters.com/finance/currencies/quote?srcAmt=1.00&srcCurr=USD&destAmt=&destCurr=ASD&historicalDate=MMddyyyy"
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
req.Timeout = 3000000;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
   // ...
}

但是在我的Windows服务中,GetResponse()抛出异常,"远程名称无法解析:'www.reuters.com'"。

我不知道我做错了什么,也许我在ServiceInstaller中设置了错误。

谢谢你告诉我正确的路线,但是还有一个问题。

我在做虚拟机(我有管理员权限,但是我没有任何管理经验)。

如果我在服务安装程序中为用户设置帐户(并提供我的登录详细信息),那么我与数据库(Odbc)的连接有问题。连接打开抛出:

ERROR [08001] [MERANT][ODBC Sybase driver]
Allocation of a Sybase Open Client Context failed.  
Sybase normally generates a SYBINIT.ERR file containing more specific reasons for failing.'r'n
ERROR [01S00] [MERANT][ODBC Sybase driver]
Invalid attribute in connection string: Port.

因此,如果在ServiceInstaller中设置帐户用户,我无法连接到DB,否则,如果我将帐户设置为LocalSystem,我可以打开连接到DB,但我不能使用GetResponse()

所以问题是,当所有的东西都放在Windows终端服务器上时,我该怎么办?

我想可能是管理员权限出了问题。我该怎么做才能解决这个问题?再次感谢。

HttpWebResponse: Windows服务vs.控制台应用程序

Windows Service应用程序默认在LocalSystem帐户下运行,而您的控制台应用程序在您的用户帐户下运行,因此您可能会遇到权限问题(Windows防火墙?)

您应该在管理员帐户下运行服务,看看这是否解决了您的问题。