goodmorningsky Posted March 22, 2005 Posted March 22, 2005 Hi all Is there a way to verify Webservice url if it's exists or not? I have a situation that I have to verify webservice url retrieved from config file before calling Webservice. Thank you.. Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
goodmorningsky Posted March 22, 2005 Author Posted March 22, 2005 try downloading the wsdl file 1st. How can I try to download? I've used only VS.NET to get WSDL. so I don't know how to download it programmatically! Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
goodmorningsky Posted March 22, 2005 Author Posted March 22, 2005 even your web browser can do it. I means... Which method should I use? Do you have any code snippt for this? It's hard to find one... Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
HJB417 Posted March 22, 2005 Posted March 22, 2005 Here are the two simplest ways to do it using the bcl. The WebClient ,as simple as it is, is unfortunately a GUI component and therefore extends IDisposable. The HttpWebRequest object is more configurable than the WebClient, for example, you can't set the keep-alive property using the WebClient. using System; using System.Net; namespace ConsoleApplication2 { class Class1 { static void Main(string[] args) { Uri badUri = new Uri("http://www.webservicex.net/WeatherForecast.asewr"); Uri goodUri = new Uri("http://www.webservicex.net/WeatherForecast.aspx?WSDL"); Console.WriteLine("WSDL exists @ {0} = {1}", badUri, WsdlExists1(badUri)); Console.WriteLine("WSDL exists @ {0} = {1}", badUri, WsdlExists2(badUri)); Console.WriteLine("WSDL exists @ {0} = {1}", goodUri, WsdlExists1(goodUri)); Console.WriteLine("WSDL exists @ {0} = {1}", goodUri, WsdlExists2(goodUri)); } static bool WsdlExists1(Uri uri) { using(WebClient wc = new WebClient()) { try { wc.DownloadData(uri.AbsoluteUri); return true; } catch(WebException error) { HttpWebResponse response = (HttpWebResponse) error.Response; switch(response.StatusCode) { case HttpStatusCode.NotFound: return false; default: throw; } } } } static bool WsdlExists2(Uri uri) { HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); try { using(HttpWebResponse response = (HttpWebResponse) request.GetResponse()); return true; } catch(WebException error) { HttpWebResponse response = (HttpWebResponse) error.Response; switch(response.StatusCode) { case HttpStatusCode.NotFound: return false; default: throw; } } } } } Quote
goodmorningsky Posted March 22, 2005 Author Posted March 22, 2005 Thank you very much~!! I got it! Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.