你的位置:首页 > ASP.net教程

[ASP.net教程]net实现ping的方法


class ServicePinger  {    private static readonly ILog log = LogManager.GetLogger(typeof(ServicePinger));    public ServicePinger(string siteName, string siteUrl, string serviceUrl)    {      if (siteName == null)        throw new ArgumentException("siteName can't be null");       if (siteUrl == null)        throw new ArgumentException("siteUrl can't be null");       if (serviceUrl == null)        throw new ArgumentException("serviceUrl can't be null");       if (siteName.Length == 0)        throw new ArgumentException("siteName can't be empty");       if (siteUrl.Length == 0)        throw new ArgumentException("siteUrl can't be empty");       if (serviceUrl.Length == 0)        throw new ArgumentException("serviceUrl can't be empty");       pingingSiteName = siteName;      pingingSiteUrl = siteUrl;      serviceUrlToPing = serviceUrl;      }     private string pingingSiteName = string.Empty;    private string pingingSiteUrl = string.Empty;    private string serviceUrlToPing = string.Empty;    private int timeoutInMilliseconds = 3000;     /// <summary>    /// Does the actual pinging of the service    /// </summary>    public void Ping()    {      try      {        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrlToPing);        request.Method = "POST";        request.ContentType = "text/