How It Works
In the XML-RPC standard, you represent datatypes by enclosing them in specific XML tags. This example indicates the two integer parameters by enclosing them in
<i4> tags as highlighted below:
...
<param>
<value><i4>2</i4></value>
</param>
<param>
<value><i4>3</i4></value>
</param>
...
The XML-RPC clients and servers encode the data in this way, and they must map them to the appropriate equivalent platform datatype implementation. In kXML-RPC, the XML-RPC datatypes are mapped to the Java 1.3-compliant datatypes shown in Table 2.
| XML-RPC Type |
Encoding Example |
Java 1.3 Type |
| Four-byte signed integer |
<i4>263</i4>
|
java.lang.Integer |
| 0 (false) or 1 (true) |
<boolean>0</boolean>
|
java.lang.Boolean |
| String |
<string>I got no time for the jibba-jabba.</string>
|
java.lang.String |
| Date/time |
<dateTime.iso8601> 20070828T14:08:55 </dateTime.iso8601>
|
java.util.Date |
| Base-64 encoded binary |
<base64> eW91IGNhbid0I </base64>
|
byte[] |
Struct
These are name-value pairs where the name is a string used as a key to retrieve the paired value. The value can be of any valid XML-RPC datatype, including structs and arrays. |
<struct> <member> <name>name</name> <value> <string>Dave</string> </value> </member> <member> <name>age</name> <value> <i4>28</i4> </value> </member> </struct>
|
java.util.Hashtable |
Array
The specification for arrays allows for an ordered sequence of any type of valid XML-RPC datatype value. |
<array> <data> <value> <i4>13</i4> </value> <value> <string>Foo you!</string> </value> <value> <boolean>1</boolean> </value> </data> </array>
|
java.util.Vector |
| Table 2. Mappings from XML-RPC Datatypes to the Java 1.3-Compliant Datatypes |
The integers and boolean values do not map to int and bool primitives, but to their respective class equivalents. kXML-RPC is designed as such so that these kinds of values can be added to Vectors and Hashtables, because this is how the XML-RPC Struct and Array types are mapped respectively. Also note that when tags are not used to specify a type, the type is assumed to be a String.
kXML-RPC utilizes the kXML parser and serializer to create outgoing messages and process incoming messages. The XmlRpcClient class delegates serialization and parsing to the XmlRpcWriter and XmlRpcParser classes. Figure 1 illustrates the flow of control when the execute method of XmlRpcClient is called.
| Figure 1. Flow of Control When Execute Method of XmlRpcClient Is Called |
The XmlRpcWriter class creates the XML-RPC message and uses an HTTP POST request to send the message to a web service. The payload of the HTTP response is then processed by the XmlRpcParser, where the resulting object is finally returned by the execute method.
XML-RPC Limitations
XML-RPC provides a simple, minimalist XML grammar for invoking service operations. It does not, however, lend itself well to more advanced scenarios. Securing XML-RPC messages is limited to Transport Level Security (TLS) or ad-hoc XML encryption. Additionally, the protocol provides no extension mechanism to facilitate exchange of security tokens, transaction semantics, conversational state, endpoint addressing, intermediary handling, or other enterprise-grade messaging capabilities. If these more sophisticated capabilities are a part of your system requirements, then XML-RPC is not the answer. If, however, you're looking for a quick, streamlined means of exchanging simple data structures between two systems in a neutral fashion, then XML-RPC is just right.
SOA Goes Wireless
As SOA continues to become a more pervasive factor within enterprise information systems, its convergence with mobile computing is inevitable. Service orientation is going wireless; it's simply a matter of how much and how soon. When this occurs, enterprises will need to evaluate their requirements and make a determination regarding the right messaging protocol. XML-RPC and the kXML-RPC library certainly are in the mix.