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

时间:2011-10-11 09:31:18

标签: c# windows-services console-application httpwebresponse getresponse

我有一个问题,我两天都无法解决。

在控制台应用中,此代码可以正常工作:

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中设置帐户用户我无法连接到数据库,否则如果我将帐户设置为LocalSystem,我可以打开与数据库的连接,但我无法使用GetResponse()

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

我想可能会有一些与管理员权限混淆的事情。我该怎么做才能解决这个问题?再次感谢。

1 个答案:

答案 0 :(得分:1)

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

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