• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    .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/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压缩功能实现方法
    下一篇:php基础练习--简单验证码实现
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    .net实现ping的实例代码 .net,实现,ping,的,实例,代码,