Net ping method, net ping method

Source: Internet
Author: User

Net ping method, net ping method

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/xml";                request.Timeout = timeoutInMilliseconds;                request.Credentials = CredentialCache.DefaultNetworkCredentials;                  Stream stream = (Stream)request.GetRequestStream();                using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII))                {                    writer.WriteStartDocument();                    writer.WriteStartElement("methodCall");                    writer.WriteElementString("methodName", "weblogUpdates.ping");                    writer.WriteStartElement("params");                    writer.WriteStartElement("param");                    writer.WriteElementString("value", pingingSiteName);                    writer.WriteEndElement();                    writer.WriteStartElement("param");                    writer.WriteElementString("value", pingingSiteUrl);                    writer.WriteEndElement();                    writer.WriteEndElement();                    writer.WriteEndElement();                }                  request.GetResponse();            }            catch (InvalidOperationException ex)            {                log.Error(ex);            }            catch (NotSupportedException ex)            {                log.Error(ex);            }           }     }

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.