363 lines
6.4 KiB
HTML
363 lines
6.4 KiB
HTML
<HTML
|
||
><HEAD
|
||
><TITLE
|
||
>What is XML-RPC?</TITLE
|
||
><META
|
||
NAME="GENERATOR"
|
||
CONTENT="Modular DocBook HTML Stylesheet Version 1.63
|
||
"><LINK
|
||
REL="HOME"
|
||
TITLE="XML-RPC HOWTO"
|
||
HREF="index.html"><LINK
|
||
REL="PREVIOUS"
|
||
TITLE="Legal Notice"
|
||
HREF="xmlrpc-howto-legal.html"><LINK
|
||
REL="NEXT"
|
||
TITLE="XML-RPC vs. Other Protocols"
|
||
HREF="xmlrpc-howto-competition.html"></HEAD
|
||
><BODY
|
||
CLASS="section"
|
||
BGCOLOR="#FFFFFF"
|
||
TEXT="#000000"
|
||
LINK="#0000FF"
|
||
VLINK="#840084"
|
||
ALINK="#0000FF"
|
||
><DIV
|
||
CLASS="NAVHEADER"
|
||
><TABLE
|
||
WIDTH="100%"
|
||
BORDER="0"
|
||
CELLPADDING="0"
|
||
CELLSPACING="0"
|
||
><TR
|
||
><TH
|
||
COLSPAN="3"
|
||
ALIGN="center"
|
||
>XML-RPC HOWTO</TH
|
||
></TR
|
||
><TR
|
||
><TD
|
||
WIDTH="10%"
|
||
ALIGN="left"
|
||
VALIGN="bottom"
|
||
><A
|
||
HREF="xmlrpc-howto-legal.html"
|
||
>Prev</A
|
||
></TD
|
||
><TD
|
||
WIDTH="80%"
|
||
ALIGN="center"
|
||
VALIGN="bottom"
|
||
></TD
|
||
><TD
|
||
WIDTH="10%"
|
||
ALIGN="right"
|
||
VALIGN="bottom"
|
||
><A
|
||
HREF="xmlrpc-howto-competition.html"
|
||
>Next</A
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><HR
|
||
ALIGN="LEFT"
|
||
WIDTH="100%"></DIV
|
||
><DIV
|
||
CLASS="section"
|
||
><H1
|
||
CLASS="section"
|
||
><A
|
||
NAME="xmlrpc-howto-intro"
|
||
>2. What is XML-RPC?</A
|
||
></H1
|
||
><P
|
||
><A
|
||
HREF="http://www.xmlrpc.com/"
|
||
TARGET="_top"
|
||
>XML-RPC</A
|
||
> is a simple,
|
||
portable way to make remote procedure calls over HTTP. It can be used
|
||
with Perl, Java, Python, C, C++, PHP and many other programming
|
||
languages. Implementations are available for Unix, Windows and the
|
||
Macintosh.</P
|
||
><P
|
||
>Here's a short XML-RPC client written in Perl. (We use Ken
|
||
MacLeod's <A
|
||
HREF="http://bitsko.slc.ut.us/~ken/xml-rpc/"
|
||
TARGET="_top"
|
||
>Frontier::Client</A
|
||
>
|
||
module.)</P
|
||
><TABLE
|
||
BORDER="0"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="100%"
|
||
><TR
|
||
><TD
|
||
><PRE
|
||
CLASS="programlisting"
|
||
>use Frontier::Client;
|
||
$server = Frontier::Client->new(url => 'http://betty.userland.com/RPC2');
|
||
$name = $server->call('examples.getStateName', 41);
|
||
print "$name\n";</PRE
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>When run, this program will connect to the remote server, get the
|
||
state name, and print it. (State #41 should be South Dakota in this
|
||
example.)</P
|
||
><P
|
||
>Here's the same program in Python. (This time, we use Fredrik
|
||
Lundh's <A
|
||
HREF="http://www.pythonware.com/products/xmlrpc/"
|
||
TARGET="_top"
|
||
>xmlrpclib</A
|
||
>.)</P
|
||
><TABLE
|
||
BORDER="0"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="100%"
|
||
><TR
|
||
><TD
|
||
><PRE
|
||
CLASS="programlisting"
|
||
>python> import xmlrpclib
|
||
python> server = xmlrpclib.Server("http://betty.userland.com/RPC2")
|
||
python> server.examples.getStateName(41)
|
||
'South Dakota'</PRE
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>In the following chapters, you'll learn how to write XML-RPC
|
||
clients and servers in a variety of programming languages.</P
|
||
><DIV
|
||
CLASS="section"
|
||
><H2
|
||
CLASS="section"
|
||
><A
|
||
NAME="xmlrpc-howto-spec"
|
||
>2.1. How it Works</A
|
||
></H2
|
||
><P
|
||
>XML-RPC is described fully in Dave Winer's <A
|
||
HREF="http://www.xmlrpc.com/spec"
|
||
TARGET="_top"
|
||
>official specification</A
|
||
>. If
|
||
you're curious, go ahead and take a look—it's a quick and
|
||
straight-forward read.</P
|
||
><P
|
||
>On the wire, XML-RPC values are encoded as XML:</P
|
||
><TABLE
|
||
BORDER="0"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="100%"
|
||
><TR
|
||
><TD
|
||
><PRE
|
||
CLASS="programlisting"
|
||
><methodCall>
|
||
<methodName>sample.sumAndDifference</methodName>
|
||
<params>
|
||
<param><value><int>5</int></value></param>
|
||
<param><value><int>3</int></value></param>
|
||
</params>
|
||
</methodCall></PRE
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>This is verbose, but compresses readily. It's also faster than
|
||
you might expect—according to measurements by Rick Blair, a
|
||
round-trip XML-RPC call takes 3 milliseconds using Hannes
|
||
Walln<6C>fer's Java implementation.</P
|
||
></DIV
|
||
><DIV
|
||
CLASS="section"
|
||
><H2
|
||
CLASS="section"
|
||
><A
|
||
NAME="xmlrpc-howto-types"
|
||
>2.2. Supported Data Types</A
|
||
></H2
|
||
><P
|
||
>XML-RPC supports the following data types:</P
|
||
><P
|
||
></P
|
||
><DIV
|
||
CLASS="variablelist"
|
||
><DL
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>int</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>A signed, 32-bit integer.</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>string</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>An ASCII string, which may contain NULL bytes. (Actually,
|
||
several XML-RPC implementations support Unicode, thanks to the
|
||
underlying features of XML.)</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>boolean</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>Either true or false.</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>double</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>A double-precision floating point number. (Accuracy may
|
||
be limited in some implementations.)</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>dateTime.iso8601</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>A date and time. Unfortunately, since XML-RPC forbids the
|
||
use of timezones, this is very nearly useless.</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>base64</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>Raw binary data of any length; encoded using Base64 on
|
||
the wire. Very useful. (Some implementations don't like to
|
||
receive zero bytes of data, though.)</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>array</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>An one-dimensional array of values. Individual values may
|
||
be of any type.</P
|
||
></DD
|
||
><DT
|
||
><TT
|
||
CLASS="literal"
|
||
>struct</TT
|
||
></DT
|
||
><DD
|
||
><P
|
||
>A collection of key-value pairs. The keys are strings;
|
||
the values may be of any type.</P
|
||
></DD
|
||
></DL
|
||
></DIV
|
||
></DIV
|
||
><DIV
|
||
CLASS="section"
|
||
><H2
|
||
CLASS="section"
|
||
><A
|
||
NAME="xmlrpc-howto-history"
|
||
>2.3. The History of XML-RPC</A
|
||
></H2
|
||
><P
|
||
>XML-RPC was inspired by two earlier protocols. The first is an
|
||
anonymous RPC protocol designed by Dave Winer and announced in an
|
||
<A
|
||
HREF="http://davenet.userland.com/1998/02/27/rpcOverHttpViaXml"
|
||
TARGET="_top"
|
||
>old
|
||
DaveNet essay</A
|
||
>. (This is why XML-RPC servers are often
|
||
installed under <TT
|
||
CLASS="filename"
|
||
>/RPC2</TT
|
||
>.) The other, more
|
||
important inspiration was an early draft of the SOAP protocol.</P
|
||
><P
|
||
>A longer <A
|
||
HREF="http://www.xmlrpc.com/stories/storyReader$555"
|
||
TARGET="_top"
|
||
>history of
|
||
XML-RPC</A
|
||
> has been generously provided by Dave Winer. This also
|
||
explains the relationship between XML-RPC and SOAP.</P
|
||
></DIV
|
||
></DIV
|
||
><DIV
|
||
CLASS="NAVFOOTER"
|
||
><HR
|
||
ALIGN="LEFT"
|
||
WIDTH="100%"><TABLE
|
||
WIDTH="100%"
|
||
BORDER="0"
|
||
CELLPADDING="0"
|
||
CELLSPACING="0"
|
||
><TR
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="left"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="xmlrpc-howto-legal.html"
|
||
>Prev</A
|
||
></TD
|
||
><TD
|
||
WIDTH="34%"
|
||
ALIGN="center"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="index.html"
|
||
>Home</A
|
||
></TD
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="right"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="xmlrpc-howto-competition.html"
|
||
>Next</A
|
||
></TD
|
||
></TR
|
||
><TR
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="left"
|
||
VALIGN="top"
|
||
>Legal Notice</TD
|
||
><TD
|
||
WIDTH="34%"
|
||
ALIGN="center"
|
||
VALIGN="top"
|
||
> </TD
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="right"
|
||
VALIGN="top"
|
||
>XML-RPC vs. Other Protocols</TD
|
||
></TR
|
||
></TABLE
|
||
></DIV
|
||
></BODY
|
||
></HTML
|
||
> |