温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:
LiveBlog/LiveBlog.Core/Ping/PingService.cs,打开代码结构图
LiveBlog/LiveBlog.Core/Ping/PingService.cs,打开代码结构图1Using 13
14
namespace LiveBlog.Core.Ping 15
{ 16
/// <summary> 17
/// Pings various blog ping services. 18
/// <remarks> 19
/// Whenever a post is created or updated, it is important 20
/// to notify the ping services so that they have the latest 21
/// updated posts from the blog. 22
/// </remarks> 23
/// </summary> 24
public static class PingService 25
{ 26
/// <summary> 27
/// Sends a ping to various ping services asynchronously. 28
/// </summary> 29
public static void Send() 30
{ 31
StringCollection services = BlogService.LoadPingServices(); 32
foreach (string service in services) 33
{ 34
Execute(service); 35
} 36
} 37
38
/// <summary> 39
/// Creates a web request and invokes the response asynchronous. 40
/// </summary> 41
private static void Execute(string url) 42
{ 43
try 44
{ 45
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 46
request.Method = "POST"; 47
request.ContentType = "text/xml"; 48
request.Timeout = 3000; 49
request.Credentials = CredentialCache.DefaultNetworkCredentials; 50
51
AddXmlToRequest(request); 52
request.GetResponse(); 53
} 54
catch (Exception) 55
{ 56
// Log the error. 57
} 58
} 59
60
/// <summary> 61
/// Adds the XML to web request. The XML is the standard 62
/// XML used by RPC-XML requests. 63
/// </summary> 64
private static void AddXmlToRequest(HttpWebRequest request) 65
{ 66
Stream stream = (Stream)request.GetRequestStream(); 67
using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII)) 68
{ 69
writer.WriteStartDocument(); 70
writer.WriteStartElement("methodCall"); 71
writer.WriteElementString("methodName", "weblogUpdates.ping"); 72
writer.WriteStartElement("params"); 73
writer.WriteStartElement("param"); 74
writer.WriteElementString("value", BlogSettings.Instance.Name); 75
writer.WriteEndElement(); 76
writer.WriteStartElement("param"); 77
writer.WriteElementString("value", Utils.AbsoluteWebRoot.ToString()); 78
writer.WriteEndElement(); 79
writer.WriteEndElement(); 80
writer.WriteEndElement(); 81
} 82
} 83
} 84
}





