WordPress – there I Fixed That For You
I’ve been having a problem with Windows Live Writer after I installed a WordPress plugin, Now Reading. That plugin allows me to show the books I’m currently reading on the sidebar.
If I have that plugin enabled, I would get the error above, “Invalid Server Response – The response to the blogger.getUsersBlogs method received from the blog server was invalid: Invalid response document returned from XmlRpc server”. Many people have encountered that error and I was able to find several solutions but none of them fixed my problem. Being a rock star programmer, I decided that I would lick this problem and continue to use my plugin with Windows Live Writer. I believe in bending computers to my will instead of living with their problems.
In plain English the error message means the XML response from WordPress does not validate because it is not valid XML. I don’t know why they could not say that in the error message. You can tell it was written by a Microsoft employee!
In order to troubleshoot this problem you need to see the XML response. I did find a XML-RPC debugger at: http://gggeek.raprap.it/debugger/ but it is not very helpful when the XML is malformed. It can give you some insight into the methods that are available though. In order to figure out exactly what was going on, I wrote a simple VBScript to submit a POST request to the xmlrpc.php file and saved the response to a file. That’s right, I used VBScript! VBScript is perfect for simple tasks that do not warrant a lot of effort.
1: ' #################################################
2: ' # VBScript To Call WordPress XMLRPC #
3: ' # Need to examine XML response to troubleshoot #
4: ' # programmed by Robert S. Robbins on 06/10/2009 #
5: ' #################################################
6:
7: Set oXMLHTTP = WScript.CreateObject("MSXML2.XMLHTTP")
8: oXMLHTTP.open "POST", "http://www.williamsportwebdeveloper.com/cgi/wp/xmlrpc.php",False
9:
10: oXMLHTTP.setRequestHeader "Content-Type", "text/xml"
11: 'oXMLHTTP.send "<?xml version='1.0'?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>"
12: oXMLHTTP.send "<?xml version='1.0'?><methodCall><methodName>demo.sayHello</methodName><params></params></methodCall>"
13:
14: 'MsgBox oXMLHTTP.responseText,vbInformation, "XMLRPC Response"
15:
16: Set fso = WScript.CreateObject("Scripting.FileSystemObject")
17: strWorkingDirectory = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName,"\")-1)
18: ' unicode format designator -1 solves the "Invalid procedure call or argument" error
19: Set objOutputFile = fso.CreateTextFile(strWorkingDirectory & "\wp-response.xml", True, -1)
20: objOutputFile.Write oXMLHTTP.responseText
21: Set objOutputFile = Nothing
22:
23: MsgBox "Done Processing!"
This script calls a XmlRpc method, it does not matter which one, and saves the result to a file. I was able to determine that the XML was invalid because 2 characters where truncated from the end of the last tag.
I’m not exactly sure why two characters get truncated with that plugin enabled but I did find the closing tag in the class-IXR.php file in the wp-includes directory. This file uses a XML template contained within within a nowdoc string, a PHP string that is not parsed. Apparently this is a PHP version of the <![CDATA[ ]]> construct but is meant to exclude quotes from parsing. Anyway, I was able to solve my problem by adding two more line breaks before the closing EOD;. This may not be the only problem with your XML. I also had a problem with a BOM (Byte Order Mark) that Microsoft Expression Web sneakily added to a PHP file I edited (Thanks, Expression Web, that was real sly of you). But I recently upgraded WordPress and I only had to apply my hack to the class-IXR.php file to get Windows Live Writer to accept the XML response from my WordPress blog.