如果不用组件,可以用下列方法:
public bool IsWebServiceAvaiable(String url)
{
try
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
using(HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse())
{
return true;
}
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
XXX.LogMessage(String.Format("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode));
XXXX.LogMessage(String.Format("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription));
}
}
catch (Exception e)
{
XXX.LogMessage(e.Message);
}
return false;
}