Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
System.Net.NetworkInformation.Ping lObjPing = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply lObjPingReply = null;

lObjPingReply = lObjPing.Send(URL);

Please help out.
Thanks
Sreenath
Posted
Updated 24-Nov-11 18:42pm
v2
Comments
[no name] 25-Nov-11 0:41am    
Do you mean how to check if web service URL exists?
Sreenath Gv 25-Nov-11 0:42am    
yeah.
JF2015 25-Nov-11 0:42am    
Edited to add code formatting.

 
Share this answer
 
Comments
Sreenath Gv 25-Nov-11 5:30am    
hi..but this didnt worked for me.
I tried this

HttpWebRequest lObjReq = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse lObjReponse = (HttpWebResponse)lObjReq.GetResponse();

but it is throwing 401 for every link.
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);
}
 
Share this answer
 
Comments
Sreenath Gv 25-Nov-11 5:09am    
also, when ever I am trying to ping web service for example

http://xx.xx.xx.xx/MyService/Service.asmx

but I am getting following error An exception occurred during a Ping request. But while browsing, it shows all the methods.

what will be the error here.

With this I got doubt whether I can use Ping for web servie or URL check.

I have already tried this ping.
C#
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;
                    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900