Perl Tutorials - Herong's Tutorial Examples - Version 5.30, by Dr. Herong Yang

Defining a Remote Method Call in XML

This section describes how a remote method call can be defined in XML format. The root element name is 'methodCall'.

The first item of the XML-RPC specification is about how to define a remote method call in XML.

XML-RPC defines a method call as an XML element called "methodCall". I have tried to find a copy of the official XML Schema Definition (XSD) of "methodCall". But I had no success. So I wrote one myself. It is definitely not 100% accurate. But it does show you how the "methodCall" XML structure should be.

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- xmlRpcMethodCall.xsd
     Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
-->
 <xsd:element name="methodCall" type="methodCallType"/>
 <xsd:complexType name="methodCallType">
  <xsd:sequence>
   <xsd:element name="methodName" type="xsd:string" 
      minOccurs="1" maxOccurs="1"/>
   <xsd:element name="params" type="paramsType" 
      minOccurs="0"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="paramsType">
  <xsd:sequence>
   <xsd:element name="param" type="paramType" 
      minOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="paramType">
  <xsd:sequence>
   <xsd:element name="value" type="valueType" 
      minOccurs="1" maxOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="valueType">
  <xsd:choice>
   <xsd:element name="int" type="xsd:int" />
   <xsd:element name="boolean" type="xsd:boolean" />
   <xsd:element name="string" type="xsd:string" />
   <xsd:element name="double" type="xsd:double" />
   <xsd:element name="dateTime.iso8601" type="xsd:string" />
   <xsd:element name="base64" type="xsd:xsd:base64Binary" />
   <xsd:element name="struct" type="structType" />
   <xsd:element name="array" type="arrayType" />
  </xsd:choice>
 </xsd:complexType>
 <xsd:complexType name="structType">
  <xsd:sequence>
   <xsd:element name="member" type="memberType"
      minOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="memberType">
  <xsd:sequence>
   <xsd:element name="name" type="xsd:string"
      minOccurs="1" maxOccurs="1"/>
   <xsd:element name="value" type="valueType"
      minOccurs="1" maxOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="arrayType">
  <xsd:sequence>
   <xsd:element name="data" type="dataType"
      minOccurs="1" maxOccurs="1"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="dataType">
  <xsd:sequence>
   <xsd:element name="value" type="valueType"
      minOccurs="0"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>

From this XML schema, we can see that:

  • A "methodCall" element will have a required "methodName" element and an optional "params" element.
  • A "methodName" element specifies the name of the method.
  • A "params" element specifies a list of "param" elements as parameters for the method.
  • A "param" element will have a "value" element.
  • A "value" element will have a value type element, which contains the actual value of the parameter.
  • There are 7 value type elements: "int", "boolean", "string", "double", "dateTime.iso8601", "base64", "struct" and "array". The first 6 are simple elements and the last 2 are complex elements.
  • A "struct" element will have a list of "member" elements. A "member" element will have a "name" element and a "value" element.
  • An "array" element will have a "data" elements, which will have a list of "value" elements.

The following is an example of "methodCall":

<methodCall>
 <methodName>somePackage.someSort</methodName>
 <params>
  <param><value><int>3</int></value></param>
  <param><value><string>Descending</string></value></param>
  <param><value><struct>
   <member><name>Yang</name><value><int>9647</int></value></member>
   <member><name>Bush</name><value><int>3014</int></value></member>
   <member><name>Gate</name><value><int>6618</int></value></member>
  </struct></value></param>
 </params>
</methodCall>

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

XML-RPC - Remote Procedure Call with XML and HTTP

 What Is XML-RPC?

Defining a Remote Method Call in XML

 Sending a Remote Method Call as a HTTP Request

 Defining Returning Values of a Remote Method Call

 Receiving Returning Values as a HTTP Response

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 References

 Printable Copy - PDF Version

Defining a Remote Method Call in XML - Updated in 2014, by Dr. Herong Yang