无法使用Windows Service解析主机名 [英] Unable to resolve host name using Windows Service

查看:347
本文介绍了无法使用Windows Service解析主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在VS2005 c#中从事Windows服务项目的工作,该项目将定期监视数据库状态,并在出现任何问题时将SMS发送给相关人员.

现在的问题是,连接到Internet发送SMS时,webclient类对象出现错误:
无法解析远程名称".

但是在单击某些按钮时,相同的代码也可与WindowsApplication一起使用.凭据有什么区别.


代码如下:

Hi All,
I am working on windows service project in VS2005 c#, which monitors Database status after regular intervals and in case of any problem sends SMS to concerned person.

Now the problem is that when connecting to internet for sending SMS, the webclient class object through an error:
"The remote name could not be resolved".

But same code is working with windowsApplication on some button click. Is there any difference in credentials.


Code is as follow:

protected override void OnStart(string[] args)
{            
WebClient webClient = new WebClient();
try
{
   wtr = new StreamWriter(@"c:\SMS.txt");
   wtr.WriteLine("sms Application");                
   string sms = webClient.DownloadString("http://www.google.com");//Sample Domain
   wtr.WriteLine("sms");
   wtr.Close();   
}
catch (Exception ex)
{
   wtr.WriteLine(ex.Message);
   wtr.Close();                
}
}




预先感谢




Thanx in advance

推荐答案

您是否尝试过
Did you try this[^]? Try using the suggested methods, I am sure you will find a solution. If you still cannot solve it, come back and give more details of what you tried.

Hope it helps!


这篇关于无法使用Windows Service解析主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆