I'm trying to develop a Pingback Server. The specification requires a method name "pingback.ping" and I couldn't figure out how to get a period into the method name so I didn't use a web service.
It will be called via an HTTP POST that conforms to the
XML-RPC Specification. Since I couldn't get it to work as a web service I figured I could just read the whole thing in from the request as a normal web page; then parse the XML.
I've tried hosting it within VS 2008, IIS7 (Vista) and IIS6 (Server 2003). It worked once, on my local IIS7 (Vista), and once on the IIS6 box.
The page is being called by this code in another project (Which I've confirmed does work, despite lack of elegance)
protected void Page_Load(object sender, EventArgs e) {
string strPost = MV4.Interop.HTTP.CreateXmlRpcPostString("http://Source.example.com", http://target.example.com);
string PingbackServer = "http://kcws/pingback";
string strResp = MV4.Interop.HTTP.PostURL(PingbackServer, strPost);
Response.Write(strResp); }
public static string PostURL(string url, string e) {
// Inits
url = url.ToLower().Trim();
if (url == null || (!url.StartsWith("http://") && !url.StartsWith("https://"))) return null;
if (e == null) e = "";
string ReturnStr = "";
System.IO.StreamWriter myWriter;
System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = e.Length;
objRequest.ContentType = "text/xml";
objRequest.KeepAlive = false;
objRequest.UserAgent = "ZI255 BattleBot";
myWriter = new System.IO.StreamWriter(objRequest.GetRequestStream());
try { myWriter.Write(e); }
catch (Exception ex) { return ex.ToString(); }
finally { myWriter.Close(); }
System.Net.HttpWebResponse objResponse;
System.IO.StreamReader sr = null;
try {
objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();
sr = new System.IO.StreamReader(objResponse.GetResponseStream()); }
catch (Exception ex) {
if (ex.ToString().Contains("(405) Method Not Allowed.")) return "Error: Server does not support this method."; }
ReturnStr = sr.ReadToEnd();
sr.Close();
myWriter.Close();
return ReturnStr; }
public static string CreateXmlRpcPostString(string SourceURI, string TargetURI) {
return "<?xml version=\"1.0\"?>\r\n" +
"<methodCall>\r\n" +
" <methodName>ping.pingback</methodName>\r\n" +
" <params>\r\n" +
" <param>\r\n" +
" <value><string>" + SourceURI + "</string></value>\r\n" +
" </param>\r\n" +
" <param>\r\n" +
" <value><string>" + TargetURI + "</string></value>\r\n" +
" </param>\r\n" +
" </params>\r\n" +
"</methodCall>"; }
The server is upstairs; it's configured pretty much to default settings (on that virtual folder). It's also hosting my blogs, but those don't need POSTs 