【发布时间】:2010-10-04 10:48:00
【问题描述】:
我有一个网络服务,我通过 PDA 与之交谈。在与 webservice asmx 文件相同的目录中,我有一个 html 文件,我从中提取一个 web 请求,以查看该目录是否可用。
我使用以下代码:
/// <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;
}
}
我收到响应的文件始终相同,并且始终可以从我的 PC 访问。仅当 Web 服务(与 html 文件位于同一目录中)错误时,它似乎才会失败。会不会有关系?
或者,有没有更好的方法来查看该文件是否存在于网络上?
【问题讨论】:
标签: web-services windows-mobile compact-framework c#-2.0