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

C# HttpWebResponse:Windows服务与控制台应用程序,c#,windows-services,console-application,httpwebresponse,getresponse,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

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

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

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
中设置Account User,我就无法连接到数据库,如果将Account设置为LocalSystem,我就可以打开到数据库的连接,但不能使用
GetResponse()

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


我想可能是管理权限出了问题。我能做些什么来解决这个问题?再次感谢。

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

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