1

Resolved

Include xml declaration in xmlrpc

description

I have recently set up a website that uses Orchard 1.5.1, I attempted to use an application called Blogsy to publish content from my iPad however the application was generating an error when using the xmlrpc. After some investigation and an exchange of emails between myself and the team at Blogsy they identified the problem. It turns out that their application is looking for the xml declaration <?xml version="1.0" encoding="utf-8"?> in the response message from service call. After looking at the code for the XmlRpc -> HomeController I noticed that the XElement is converted to a string and output as content. I modified to write to the response stream directly, this way the xml declaration is included in the response.
        var content = _writer.MapMethodResponse(methodResponse);

        this.Response.ContentType = "text/xml";
        content.Save(this.Response.OutputStream);
Is this something that could be fixed? There are only a handful of applications on the iPad for blogging. I think it would be good if Orchard was supported.

comments

sebastienros wrote Aug 23, 2012 at 8:09 PM

We need to ensure that is was never done like this before in the history of the file, otherwise it might mean that is was converted to text for a specific reason. Otherwise we need to find another technique.

RohanWest wrote Aug 24, 2012 at 12:13 AM

I had a look at the history for Orchard.Core.XmlRpc.Controllers.HomeController and it appears that the action has always returns content without the xml declaration. Looking at various implementations of the xmlrpc it appears that they include the xml declaration.

http://xmlrpc.scripting.com/spec.html
http://en.wikipedia.org/wiki/XML-RPC

sebastienros wrote Sep 24, 2012 at 10:36 PM

Fixed in changeset 38509f41229b

JasperD wrote Sep 25, 2012 at 7:44 PM

This fix actually reverts to changeset 82ca0052159d. After 82ca a fix for "#18615 XmlRpc : blogger.getUsersBlogs returns an error" was checked in (6c2ed0505c70) that removed the xml declaration from the response stream, hence #18615 should be active again.

I have investigated the problem a bit further: some XML-RPC libraries (I've tested XML-RPC.NET and XML-RPC for PHP seems to be affected too (used by the tool mentioned in #18615)) does not validate XML that contains encoding="UTF-16". Since the StringWriter that is passed in the Save method uses UTF-16 as default encoding and overrides settings made in XDocument objects, I suggest using a custom StringWriter that either has no encoding to omit the enconding in the XML declaration completely or using a StringWriter with UTF-8, both works (e.g. http://pastebin.com/mSYtaUEL).

sfmskywalker wrote Mar 28 at 1:28 AM

Fixed in changeset dab9b332cdeba91e4abeb4d9d2a1518a1c8f1a88