What is XML-RPC? Details and functions
By Jithin on December 13th, 2016
What is XML-RPC
The XML-RPC is a XML based protocol. It is a simple protocol used to exchange information between computer systems over a network. It is a remote procedure call and it uses XML to encode the calls. The XML-RPC uses HTTP for transport. It allows complex data structures to be transmitted and processed. The XML-RPC protocol was created by Dave winer in 1998.
The XML-RPC will help you if you want to integrate multiple computing environments without need to share the complex data structures directly. The communication between computers over a network can be established fast and easily with the help of XML-RPC. It can be used in association with Perl, Java, Python, C, C++, PHP and many other programming languages. ie., it will allow java to communicate with Perl, Python, ASP, and so on. Let’s see how does the XML-RPC work. An XML-RPC message is actually an HTTP-POST request. There are requests and responses. The request’s body will be in XML. A procedure executes on the server. It will return a value and this value also will be in the XML format. The procedure parameters can be numbers, strings, scalars, dates, … Let’s have a look on the formats of XML-RPC requests and responses in this documentation.
XML-RPC supported Data Types
Let’s have a look on the various data types that is supported by XML-RPC. They are listed below. These data types are explained below.
These are the types of data that are supported by XML-RPC. Each data type is explained below with examples.
int: The int data type represents an integer. This is an integer which is of the following format. It is a signed integer and it is 32-bit in size.
double: It is a floating-point number. It is of double precision. In some implementations, the accuracy may vary for this data type.
boolean: It represents the boolean operations the ‘true’ and ‘false’.
dateTime.iso8601: As the name indicates, this is the data type used for a date and time. For the XML-RPC, it is quite useless because the XML-RPC forbids the use of time zones.
string: This data type represents an ASCII string. It can also have NULL bytes.
base64: All the raw binary data of any length will be encoded using this data type.
array: The array data type is familiar to all developers. Here, it is the one-dimensional array structure.
struct: In XML-RPC, there can have many key-value pairs. These pairs will be stored using the struct data type.
The following is a sample XML-RPC request.
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Here, the format of the URI in the first line of the header is not specified. If the server is only handling XML-RPC calls, this can be empty or a single slash. But, if the server is handling the HTTP requests also, we can allow the URI to route the request to the code which handles XML-RPC requests. That’s why we’ve used /RPC2 which will tell the server to route the XML-RPC request to the RPC2 responder. The next two lines are the User-Agent and Host. These must be specified on the header. The fourth line in the above example describes that the Content-Type is text/xml. The last line provides the Content-length. It must be specified correctly.
The Payload format
The Payload is also formatted in XML. It is a <methodCall> structure. It must contain a <methodName> as a sub item. This should be a string. It needs to contain the name of the method that must be called. There is no specific format for this string. As other strings, it can contain identifier characters, upper and lower-case alphabets, integers, underscore, dot, colon, and slash. The method name can be the name of the file which contains a script that will execute an incoming request. Suppose the procedure call has parameters. In this case, the <methodCall> must contain the sub item, <params> as shown in the above example.
The values can be of scalar type. The type can be indicated with the below table. As in the request,
Tag Type Example
<i4> or <int> four-byte signed integer -15
<boolean> 0 (false) or 1 (true) 1
<string> string hey there
<double> double-precision signed -15.32
floating point number
<dateTime.iso8601> date/time 19980717T14:08:55
<base64> base64-encoded binary ssecR6sdfidIJlYQdGhyE
If there is no type indicated, then it will be string by default.
The following is a sample XML-RPC response.
HTTP/1.1 200 OK
Date: Fri, 21 Aug 1994 17:45:06 GMT
Server: Example Frontier/5.1.2-WinNT
The first line is HTTP/1.1 200 OK. It will be 200 OK unless there is a lower level. As in the request, the Content-length must be specified correctly. The next line indicates Content-Type is text/xml. The body of the response is a single XML structure, a <methodResponse>, which can contain a single <params> which contains a single <param> which contains a single <value>. The <methodResponse> may also contain a <fault> with a <value>. It is actually a <struct>. It can contain two parts as <faultCode> and <faultString>. The first one will be an integer and next one will be a string.
These are the formats of an XML-RPC request and response. Please note that a <methodResponse> can’t contain a <fault> and a <params> simultaneously. It can contain any one of this.
If you need any further assistance please contact our support department.