我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

.net如何实现ping-创新互联

这篇文章主要介绍了.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;

 
        ///


        /// Does the actual pinging of the service
        ///

        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);
            }

        }

    }


感谢你能够认真阅读完这篇文章,希望小编分享的“.net如何实现ping”这篇文章对大家有帮助,同时也希望大家多多支持创新互联网站建设公司,,关注创新互联行业资讯频道,更多相关知识等着你来学习!


网页题目:.net如何实现ping-创新互联
转载源于:http://mswzjz.cn/article/dsppch.html

其他资讯