HttpWebResponse:Windows 服务与控制台应用程序
我有一个问题,两天了还没解决。
在控制台应用程序中,此代码工作正常:
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 Terminal Server 上时,我该怎么办?
我想可能是管理员权限出了问题。我可以做什么来解决这个问题?再次感谢。
I have a problem that I haven't been able to resolve for two days.
In a console app, this code works fine:
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)
{
// ...
}
But in my Windows service, GetResponse()
is throwing the exception, "The remote name could not be resolved: 'www.reuters.com'".
I have no idea what I am doing wrong, maybe I am setting something wrong in ServiceInstaller
.
Thanks for showing me the right track, but there is an additional issue.
I am working on virtual machine (I have got admin rights, but I have no experience with administration at all).
If I set account in service installer for the user (and give details of my login) then I have problems with the connection to the database (Odbc). Connection open throws me:
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.
So if set Account User in ServiceInstaller
I can't connect to the DB, else if I set Account to LocalSystem I can open connection to DB but I can't use GetResponse()
.
So the question is, what should I do when everything is placed on Windows Terminal Server?
I suppose that there could be something messed up with admin rights. What could I do to fix this? Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Windows 服务应用程序在 LocalSystem 帐户下运行,而您的控制台应用程序在您的用户帐户下运行,因此您可能会遇到权限问题(Windows 防火墙?)
您应该在管理员帐户下运行该服务,看看这是否可以解决您的问题。
Windows Service application run under the LocalSystem account by default, whereas your console app runs under your user account, you may therefore be meeting permission problems (windows firewall?)
You should run the service under the administrator account to see if this resolves your issue.