tags:

views:

1663

answers:

5

My company has been using XmlRpc for a while, but lately I'm wondering what the benefit of XmlRpc over plain XML. Firstly, it's horrible "obese", consider:

<struct><member><name>ROOM_ID</name><value><int>1</int></value></member>
<member><name>CODE</name><value><string>MR-101</string></value></member>
<member><name>NAME</name><value><string>Math Room</string></value></member>
<member><name>CAPACITY</name><value><int>30</int></value></member></struct>

Compared to this:

<room><ROOM_ID>1</ROOM_ID><CODE>MR-101</CODE>
<NAME>Math Room</NAME><CAPACITY>30</CAPACITY></room>

Or even this:

<room ROOM_ID=1 CODE=MR-101 NAME=”Math Room” CAPACITY=30 />

Secondly, XmlRpc seems fairly widespread but not quite ubiquitous and I'm not that impressed with the support for it in C++ and PHP...I've had problems with all the libraries that I tried in both languages.

Thirdly, it seems to me that I could make remote procedure calls with plain XML as easily as with XmlRpc. {(9/9/2009): Every language has libraries for serialising language-level objects into XML. Both XML and XmlRpc require application-level schemas to be defined e.g. how the fields should be spelt, but neither needs any additional schema to be defined. Many people make RPC calls with plain XML.}

So what is the value add of XmlRpc?

A: 

Let me start from the end and go backwards:

3) Yes, you could make remote procedure calls with plain XML (or plain Strings, or binary protocol). The difference is, XmlRpc is a well-defined protocol with many available implementations, which means a) you don't have to write as much code and b) you could inter-operate with whoever it is on the other end of the wire without you or them having to deal with each other's code. XmlRpc serves as a bridge.

2) I'd say it's quite ubiquitous :-) I've worked with XmlRpc in Java so can't comment on C++ / PHP implementation problems.

1) is due to (3) above. Verbosity of the protocol is both the consequence of and the reason for its interoperability.

ChssPly76
3) If I was to make remote procedure calls with plain strings or binary, this would be horrible and require designing formats for each interaction. But plain XML gives a well defined format for passing structured values. I don't think you've answered the question "what does XmlRpc have over XML?"1) My examples compare XmlRpc with XML, and prove that you don't need to be verbose to be interoperable. XML is considered a protocol which is good for interoperability.
Tim Cooper
You're wrong. Taking your example, `<room ROOM_ID=1 CODE=MR-101 NAME=”Math Room” CAPACITY=30 />` how would I know how to unmarshall that into an object if I were to receive this over a wire? It's no different from getting, say, `room|1|MR-101|Math Room|30` and relying on field order. The point is, XML-RPC provides a **well defined communication protocol** - XML by itself does not.
ChssPly76
I don't understand the point about relying on field order. In this case, the attributes (or tags) have names. Why wouldn't you look at the field names rather than the field order?
Tim Cooper
Both your XML one-liner and my pipe-separated string can successfully be used for communication between two parties. In both cases the receiving party must **ALREADY** know the object structure (your XML lacks data types, for example, not to mention its inability to convey anything but simple structure in its present form); and if I do know what I'm unmarshalling I don't really need field names. The point is - your XML examples are inadequate for real-life communication whereas XML-RPC is.
ChssPly76
XML has the ability to represent arbitrarily complex trees - I didn't get your point about "inability to convey anything but simple structure". Data types seems to be the only thing that XmlRpc adds...(although there is often a mismatch between type systems anyway between different languages.) In any XmlRpc-based protocol, there needs to be some common understanding of the object structure, e.g. what field names to expect, but XML and XmlRpc both let you add fields and reorder fields without affecting semantics. XML must be adequate for real-life communication because it's used quite widely.
Tim Cooper
Re your "quite ubiquitous" link, that's a good example of the waning interest in -- or at least lack of growth of -- XML-RPC. At least one of the links on that page points to a domain squatter's site, even though I sent the site maintainer an update 5 weeks ago. The most recent message on the mailing list is even older, and there are several other broken links on that site, some of them top-level links. Yes, I'm conflating Dave Winer's waning interest with the community's. Communities need leaders, and weak leadership means weak communities. Maybe JSON will take over from XML-RPC...
Warren Young
@Tim - I'm not sure how to explain this any clearer. Here's something that might help - write a schema (or DTD) for your 'ROOM' xml; make sure it validates. Toss in an "arbitrarily complex tree" while you're at it; don't forget method calls / results / exception mapping (this is RPC after all). Now, do the same thing for 'CAR' entity ('STOCK_TRADE', 'MEDICAL_RECORD', anything) - keep in mind that all your new XML mappings must conform to that same schema / DTD you've created. Now compare that schema to XML-RPC spec.
ChssPly76
I agree with Warren. I've checked 10 links, some of them were dead, the others were from 2002-2004.
analytik
+5  A: 

The primary advantage is that someone's already worked out the calling schema for you. This is especially helpful in languages with reflection, where you can just blindly pass, say, a complicated structure to the RPC call, and it will work out how to translate that into XML for you. It's less valuable in, say, C++, where you're having to tell the XML-RPC library what all the data types are explicitly.

You're right that it hasn't taken the world by storm. The oddities you're finding in the libraries are due to this low level of interest. I've used two myself, and found bugs in both. And both were abandonware, so there's nowhere I could send patches back to, so I have private patched versions of both. Sigh.

Warren Young
Warren, if it's possible to use reflection to serialise data-structures into XmlRpc, isn't it also possible to use reflection to serialise data-structures into plain XML?
Tim Cooper
Of course, but you have to write all that serialization code yourself, and now you've invented yet another proprietary XML schema. There's something to be said for simplicity and compatibility.
Warren Young
"Another proprietary schema" - that implies that there are more than one way to encode objects into XML. In the above example, if we simply disallow attributes, then surely there's only one way to encode the object? It's not inventing any more "proprietary schema". In fact, there are already libraries to serialise objects into plain XML for C# and PHP, and probably for most languages.
Tim Cooper
There are infinite incompatible ways to encode any given piece of data as XML. You can argue that one is better for one purpose, another encoding for another purpose, but if every purpose has a different encoding, there is no compatibility and no reused code. I am not trying to tell you that you must use XML-RPC. I am merely suggesting that you not reject it just because you like your particular wheel better. Consider the needs of those who have to write programs that read these same data structures.
Warren Young
"infinite incompatible ways to encode"? Can you suggest even a single alternative way to encode the above object in plain XML, if we apply the rule "no attributes allowed"? XmlRpc doesn't remove the need to define an application level schema e.g. how to spell the field names. Every language has a library to serialise objects into plain XML, they don't seem to think there is any choice in how to encode objects.
Tim Cooper
Hex dump of the packed binary structure form of your data above, with the integers in network byte order:<room>000000014d522d313031004d61746820526f6f6d000000001e</room>. Bonus alternative: same thing, but with bytes in a CDATA block. You might be thinking this is a silly example, but back in the day, we passed structures around like this. You might do it this way if told to move an old protocol to XML but had no budget to update old programs, so you just wrap the data in XML tags. None if this takes away from my justification for XML-RPC: compatibility and implementation simplicity.
Warren Young
+1  A: 

The primary value of XmlRpc is that you don't have to write the code to generate and parse the XML documents being passed over HTTP, since XML-RPC is a predefined XML Schema for representing function calls.

Even with less than optimal libraries, there is an additional derived value since using this type of system allows you to define your remote interfaces as basic language interfaces (C++ Abstract Class, Java interfaces, etc.), that are independent of the wire protocol used to communicate between components.

Separating the interface definitions from the wire protocol (XML-RPC, SOAP, etc.) allows you to eventually substitute in alternate protocols where appropriate. For example, in our system, we have services that are exposed using Hessian for our Flex front ends, and SOAP for our .NET front ends (the Hessian .Net library has a disallowed license).

By sticking with XML-RPC now, you have the option of switching to some other protocol in the future with minimal amounts of refactoring.

John Stauffer
With plain XML, there is no need to write code to generate and parse XML documents. I easily found links to libraries that already do this for C# and PHP in exactly the same way libraries do this for XmlRpc. If I had code that did XML then I wouldn't be interested in a multi-wire-protocol API.
Tim Cooper
+1  A: 

The short answer is: Both protocols can be used to make remote procedure calls (RPC). Both protocols require an application-level schema to be defined, and generally speaking, neither protocol requires any additional schema for defining how to serialise language-level objects (see below for some details).

However, XmlRpc enjoys greater support from libraries which use meta-programming (reflection) features of language to map XmlRpc calls, directly (well, never 100% directly) to language level function calls. The reason there is better support for XmlRpc than plain XML is either (a) a historical accident/result of marketing on the part of the XmlRpc proponents, or (b) the sum of the minor translation issues listed below tip the scales in favour of XmlRpc.

On the other hand, XmlRpc suffers from 2 main disadvantages: (1) it requires approximately 4 times as much bandwidth, and (2) it subverts the intent of XML schema-validation tools: every packet will simply be stamped as "yes, this is valid XmlRpc", regardless of spelling mistakes and omissions in application-level fields.

The long answer:

Contrary to popular belief, you don't need a standard to define how to encode language level objects in plain XML - there is generally just one "sensible" way (provided the application level schema defines whether you use XML attributes or not), e.g.:

class Room {
    int id=1;
    String code="MR-101";
    String name="Maths room";
    int capacity=30;
};

encoded as:

<Room>
    <id>1</id>
    <code>MR-101</code>
    <name>Maths room</name>
    <capacity>30</capacity>
</Room>

XmlRpc was specifically designed to facilitate the creation of libraries which automatically serialise/unserialise language-level objects in RPC calls, and as such it has some minor advantages when used in this way:

  1. With plain XML, it's possible for a struct with a single member to be confused with an array with a single element.

  2. XmlRpc defines a standard time/date format. {Although treatment of timezones and pure time or pure date timestamps is defined at the application level.}

  3. XmlRpc lets you pass arguments to the function without naming them; Plain XML RPC calls require that you name each argument.

  4. XmlRpc defines a standard way to name the method being called: "methodName". With Plain XML, the tag of the root node would typically be used for this purpose, although alternatives are possible.

  5. XmlRpc defines a simple type system: integers, strings, and so on. {Note that with statically typed languages, the types have to be compiled into the destination object anyway, and therefore are known, and with dynamically typed languages, often int's and float's and strings can be used interchangeably; note also that the XmlRpc type system would typically be a poor match for the type system of the destination language which may have multiple integer types, and so on.}

  6. XmlRpc libraries generally integrate directly with an Http library, whereas Xml serialisation libraries all(?) require the application programmer to pass the XML text to the Http call. In more modern languages such as Java/Python/C#, this is a trivial matter, but not so for e.g. C++.

  7. There is a "marketing perception" that XML describes "documents", whereas XmlRpc is designed for procedure calls. The perception is that sending an XmlRpc message contains an obligation for the server to perform some action, whereas this perception is not as strong with plain XML.

Some people will say "who cares - parsing XML data using recursive descent/DOM/SAX is pretty easy anyway", in which case most of the above objections are irrelevant.

For those who still prefer the ease of use of getting native language objects created automatically, many major languages have libraries which automatically serialise language-level objects into XML without resorting to XmlRpc, e.g.:

.NET - Java - Python

It may be that the success of XmlRpc, such as it is, stems from the availability of the libraries which automatically create language-level objects, and in turn these libraries have an advantage over their plain XML counterparts due to the list of issues above.

Disadvantages of XmlRpc are:

  • As mentioned in the question, it is horribly obese

  • Support for plain XML is ubiquitous and usually does not require integration with large 3rd party libraries. Many applications require a conversion of the automatically created objects to the application's own objects anyway.

  • Many XmlRpc implementations fail to produce true language-level objects of the sort programmers would expect and instead require e.g. run-time lookups of fields or extra syntax.

  • If a schema definition document is used to validate the RPC calls, such as a DTD file, then you lose the ability to check the application-level schema - the DTD file will simply tell you that "this is valid XmlRpc". There is not to my knowledge any standard way to define an application-level schema with an XmlRpc based protocol.

Tim Cooper
A: 

Easy: XML RPC provides

  • a standard way to pass the method name
  • a typing system. I work with phone numbers quite often, those are strings, NOT numbers.
  • a standard way to return errors
  • introspection (almost) for free

All this over standard XML.

Mauvaisours