All pastes #2001227 Raw Edit

xmlrpc ping asp.net

public text v1 · immutable
#2001227 ·published 2010-11-24 19:07 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections;

/// <summary>
/// Summary description for RPCPing
/// </summary>
public class RPCPing
{
	public RPCPing()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public string Send()
    {
        string result = "";
        ArrayList RPCServers = new ArrayList();
        RPCServers.Add("http://api.moreover.com/ping");
        RPCServers.Add("http://blogsearch.google.com/ping/RPC2");
        RPCServers.Add("http://ping.syndic8.com/xmlrpc.php");
        RPCServers.Add("http://rpc.blogrolling.com/pinger/");
        RPCServers.Add("http://rpc.icerocket.com:10080/");
        RPCServers.Add("http://ping.blo.gs/");
        RPCServers.Add("http://ping.myblog.jp");
        RPCServers.Add("http://ping.syndic8.com/xmlrpc.php");
        RPCServers.Add("http://services.newsgator.com/ngws/xmlrpcping.aspx ");

        foreach (var item in RPCServers)
        {
            try
            {
                Execute(item.ToString());
            }
            catch (Exception ex)
            {
                result = ex.Message;
                
            }
        }
        
       // Execute("http://rpc.pingomatic.com/RPC2");
        return "";
    }

    /// <summary>
    /// Creates a web request and with the RPC-XML code in the stream.
    /// </summary>
    private string Execute(string url)
    {
        string result = "";
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "text/xml";
            request.Timeout = 6000;

            AddXmlToRequest(request,"Guncel.im Sosyal İmleme","http://guncel.im/feed.aspx?Full=All");
            WebResponse WR= request.GetResponse();

            StreamReader srx = new StreamReader(WR.GetResponseStream(), System.Text.Encoding.Default);
            result= srx.ReadToEnd();
        }
        catch (Exception ex)
        {
            result = ex.Message;
            // Log the error.
        }
        return result;

    }

    /// <summary>
    /// Adds the XML to web request. The XML is the standard
    /// XML used by RPC-XML requests.
    /// </summary>
    private static void AddXmlToRequest(HttpWebRequest request,string prmWebsiteName,string prmWebsiteURL)
    {
        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");
            // Add the name of your website here
            writer.WriteElementString("value",prmWebsiteName);
            writer.WriteEndElement();
            writer.WriteStartElement("param");
            // The absolute URL of your website - not the updated or new page
            writer.WriteElementString("value", prmWebsiteURL);
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
    } 
}