如何在ASP.Net中验证Web服务URL [英] How to Validate Web Service URL in ASP.Net
本文介绍了如何在ASP.Net中验证Web服务URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何验证Web服务URL.我尝试过ping通URL,这是否是正确的方法,并且适用于所有类型的Web服务.我已经试过了:
Hi,
How can I validate web service URL. I have tried with pinging the URL, is it the right way to do so and will it work for all types of web services. I have tried this:
System.Net.NetworkInformation.Ping lObjPing = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply lObjPingReply = null;
lObjPingReply = lObjPing.Send(URL);
请帮忙.
谢谢
Sreenath
Please help out.
Thanks
Sreenath
推荐答案
尝试此链接
http://stackoverflow.com/questions/547868/how-to-check-if-a-web-service-is-available-using-net [
try this link
http://stackoverflow.com/questions/547868/how-to-check-if-a-web-service-is-available-using-net[^]
hope it helps!
Sreenath,
你可以试试看.
System.Net.NetworkInformation.Ping ping =新的System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingReply = ping.Send("www.google.com");
Console.WriteLine("ping status:{0}",pingReply.Status);
如果(pingReply.Status == IPStatus.Success)
{
Console.WriteLine(地址:{0}",pingReply.Address.ToString());
Console.WriteLine("RoundTrip时间:{0}",pingReply.RoundtripTime);
Console.WriteLine(生存时间:{0}",pingReply.Options.Ttl);
Console.WriteLine("Don" t片段:{0},pingReply.Options.DontFragment);
Console.WriteLine(缓冲区大小:{0}",pingReply.Buffer.Length);
}
Hi Sreenath,
you can try it.
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingReply = ping.Send("www.google.com");
Console.WriteLine("ping status: {0}", pingReply.Status);
if (pingReply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", pingReply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", pingReply.RoundtripTime);
Console.WriteLine("Time to live: {0}", pingReply.Options.Ttl);
Console.WriteLine("Don''t fragment: {0}", pingReply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", pingReply.Buffer.Length);
}
this worked for me..
string Http_URL = HttpUtility.UrlDecode(URL);
HttpWebRequest lObjReq = (HttpWebRequest)HttpWebRequest.Create(Http_URL);
lObjReq.Timeout = 36000;
lObjReq.UseDefaultCredentials = true;
if (lObjReq.GetResponse().ContentLength > 0)
{
Output_Err = "";
lStrLog = URL + " is a Valid URL.";
return true;
}
else
{
lStrLog = Output_Err = "Invalid URL or Web Service.";
return false;
}
这篇关于如何在ASP.Net中验证Web服务URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文