I am currently writing a custom blog application in csharp.net (c#.net). One requirement for the software was that it needed to send update information to sites like Technorati or Ping-o-matic. After some research, I’ve found that sites allow you to do this utilizing xml-rpc. The process is called pingback, but it more commenly refered to as simply pinging. Basically every time you write a new post, you can ping these services to tell them you have updated content, and let people know about it.
The specific method we want to access via xml-rpc is called “weblogUpdates.ping”. This function is implemented on all blog ping services. Below is a function which defines a list of sites to ping, then goes through and pings them one by one. It takes as parameters the name of your site, and the url of your site.
private void sendPing(String name, String url)
{
ArrayList listToPing = new ArrayList();
listToPing.Add("http://rpc.technorati.com/rpc/ping");
listToPing.Add("http://rpc.pingomatic.com");
listToPing.Add("http://blogsearch.google.com/ping/RPC2");
for (int i = 0; i < listToPing.Count; i++)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(listToPing[i].ToString());
request.Method = "POST";
request.ContentType = "text/xml";
Stream stream = (Stream)request.GetRequestStream();
using (XmlTextWriter xml = new XmlTextWriter(stream, Encoding.UTF8))
{
xml.WriteStartDocument();
xml.WriteStartElement("methodCall");
xml.WriteElementString("methodName", "weblogUpdates.ping");
xml.WriteStartElement("params");
xml.WriteStartElement("param");
xml.WriteElementString("value", name);
xml.WriteEndElement();
xml.WriteStartElement("param");
xml.WriteElementString("value", url);
xml.WriteEndElement();
xml.WriteEndElement();
xml.WriteEndElement();
xml.Close();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
string result = sr.ReadToEnd();
sr.Close();
}
response.Close();
}
}