XML-RPC.NET Types

The XML-RPC specification defines the types supported by XML-RPC.

Scalar Types

<i4> or <int> maps to System.Int32

<boolean> maps to System.Boolean

<string> maps to System.String

<double> maps to System.Double

<dateTime.iso8601> maps to System.DateTime

<base64> maps to System.Byte[]

<struct> Type

An XML-RPC struct is a dictionary of name+member pairs. The contents of the struct need not be fixed. An XML-RPC method may take a struct which need contain only a subset of the members that the server will recognize, for example the Meerkat getItems method.

In many cases an XML-RPC struct can be represented by a .NET CLS struct type. For example, methods expecting a struct parameter such as this example:

<struct>
    <member>
        <name>lowerBound</name>
        <value><i4>18</i4></value>
    </member>
    <member>
        <name>upperBound</name>
        <value><i4>139</i4></value>
    </member>
</struct>

could be defined with this C# struct as the parameter type::

struct bounds
{
    public int lowerBound;
    public int upperBound;
}


However, in some cases a variable-sized struct must be defined. In this case the XmlRpcStruct type must be used. This is derived from System.Hashtable and overrides the Add method to ensure that only keys of type String can be specified with associated values which must beXML-RPC compatible types. For example, the struct specified in the above XML could be specified in this way using XmlRpcStruct:

XmlRpcStruct bounds = new XmlRpcStruct();
bounds.Add("lowerBound", 18);
bounds.Add("upperBound", 139);

<array> Type

An XML-RPC array can be heterogeneous. Where a server is known to return an homogenous array, the XmlRpcProxy return type can be specified as as an array of that type; if not, the return type is declared of type Object[].

XML-RPC.NET supports multi-dimensional arrays - string[,] - and jagged arrays (arrays of arrays) - string[][]. The XML-RPC array type does not make this distinction and so both types of nested array are represented as nested XML-RPC structs. When deserializing the XML body of a request or a response, XML-RPC.NET can always map nested XML-RPC structs onto a jagged array, e.g. string[][], but can only map onto a multi-dimensional array if the nested arrays have equal length.

XML-RPC.NET Parameter and Return Types

To summarise the above, the parameter and return types that can be used in the current release of XML-RPC.NET are:

Structs are used as in this example:

struct Category
{
    public int id;
    public string title;
}

The members of the struct can be any valid type as described in this section and must be defined as public.

Arrays are defined in the usual way. For example,

[XmlRpcMethod("meerkat.getCategories")]
public Category[] GetCategories()
{
     return null;
}


© Charles Cook, 2001 All Rights Reserved.
24th December 2001