您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->LiveBlog v1.0测试版源码>>LiveBlog.Core/Ping/PingService.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:文件类型 LiveBlog/LiveBlog.Core/Ping/PingService.cs打开代码结构图
普通视图
		            
1Using 13 14namespace 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}
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:LiveBlog v1.0测试版源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号