Hi all, I've got a web service that I talk to from a PDA. In the same directory as the webservice asmx file, I have an html file that I pull a web request from in order to see if the directory is available.
I use the following code:
/// <summary>
/// Holds the web request for checking the connectivity.
/// </summary>
private static WebRequest m_WebRequest;
/// <summary>
/// Tests the connection to the provided URL.
/// </summary>
/// <param name="url">The URL to test.</param>
/// <returns>True if the URL was resolved.</returns>
public static bool TestUrl(string url)
{
try
{
// Ensure the url is valid
url = url.Replace("http:\\", "http://");
url = url.Replace("\\", "/");
// Create the request
m_WebRequest = WebRequest.Create(url);
m_WebRequest.Timeout = 30000;
// Get the request
HttpWebResponse response = (HttpWebResponse)m_WebRequest.GetResponse();
return true;
}
catch
{
m_WebRequest.Abort();
return false;
}
}
The file I am getting the response for is always the same and is always accessible from my PC. It only seems to fail when the web service (in the same directory as the html file) errors. Could that be related?
Alternatively, is there a better way of seeing if that file exists over the web?