1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
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);
}
}
}
|
相关文章
- 11-01网格人为干扰度计算方法的matlab代码实现
- 11-01.Net Core实现记录接口执行时间的中间件
- 11-01Ajax简单实现文件异步上传的多种方法
- 11-01nn.LayerNorm的具体实现方法(通过公式复现)
- 11-01.NET Core项目ProjectGuid无效的问题解决方法
- 11-01给自定义控件(Web Control)添加事件的几种方法。前两种方法可以不实现IPostBackEventHandler
- 11-01通过图片识别实现水文数据抓取的方法
- 11-01关于.NET中迭代器的实现以及集合扩展方法的理解
- 11-01.NET源代码的内部排序实现
- 11-01NSLayoutConstraint-代码实现自己主动布局的函数使用方法说明