XML-RPC
XML-RPC is an XML-based remote procedure call protocol that works over the Internet. The power of XML-RPC is that it can be delivered over HTTP as a POST request, the same protocol used to deliver HTML form data to servers. XML-RPC takes advantage of the existing convention by substituting an XML text document in place of form data.
Figure 1 illustrates how XML-RPC uses an HTTP POST request to transport XML-RPC. The two most widely used HTTP requests are GET and POST. GET requests a specific web page; POST delivers data from an HTML form. XML-RPC takes advantage of the POST delivery mechanism by substituting XML for the HTML form data.
Figure 1 HTTP POST is used as the transport for XML-RPC.
XML-RPC tags define a vocabulary that describes details of the remote procedure call including procedure name and parameters.
Listing 2 shows an XML-RPC encoded request for the remote execution of a procedure to retrieve the current weather forecast for New York City.
Listing 2 An XML-RPC Document
<?xml version="1.0"?> <methodCall> <methodName>getWeatherReport</methodName> <params> <param> <value><string>New York City</string></value> </param> </params> </methodCall>
The XML data has the following requirements:
The payload must be well-formed XML containing a single <methodCall> structure.
The <methodCall> element must contain a <methodName> sub-item consisting of a string with the name of the method to be called. The string can only contain identifier characters, upper- and lowercase AZ, the numeric characters 09, underscore (_), dot (.), colon (:), and slash (/). It's up to the server to decide how to interpret the characters in a <methodName>.
If the procedure call has parameters, the <methodCall> element must contain a <params> sub-item. In turn, the <params> sub-item can contain any number of <param> items, each of which has a <value>.
When a server receives an XML-RPC message packaged in a POST request, the server extracts the XML, arranges for procedure execution, and returns a result formatted as XML to the sender.
XML-RPC Advantages
XML-RPC offers several advantages over the binary protocols found in CORBA, RMI, and DCOM:
Firewalls. XML-RPC call data easily passes through firewalls, since the target port for XML-RPC is port 80, the web server port open to all Internet traffic. XML-RPC distinguishes itself from other server traffic by requiring an HTTP header element that specifies Content-type as text/xml. This alerts the server that XML is being POSTed to the server and to take appropriate action.
Discoverability. An important XML-RPC objective has been the development of a clean, extensible format that's simple to understand. The goal is for developers to be able to examine an XML-RPC procedure call, understand it, and be capable of making changes with minimal effort.
Ease of implementation. The protocol should be easily implemented so that it can be adapted quickly to run in multiple environments and operating systems.
Upcoming articles in this column will examine XML-RPC in more detail and look at its relation to SOAP, the Simple Object Access Protocol that's helping to usher in a new era of web-based services.