[Zope] ANN: Zope XML-RPC!

Eric Kidd eric@userland.com
Thu, 17 Jun 1999 16:49:27 -0400


Hello! As some of you may have guessed, I've finally gotten around to
implementing XML-RPC for Zope. You can thank the following people:

 * Jim Fulton of Digital Creations, for adding XML-RPC hooks to ZPublisher
   and answering my stupid questions.
 * Fredrik Lundh of PythonWare, for his excellent Python XML-RPC module.
 * Dave Winer of UserLand Software, who wrote the XML-RPC spec (and who
   pays my salary).

Please give all your thanks to these folks; they really *did* do all of the
work. However, I may have plugged their components together incorrectly, so
send all the blame and hate mail to me. :-)

What is XML-RPC?
----------------

XML-RPC is a very simple RPC protocol that runs over HTTP. The function
name and arguments are encoded as XML. XML-RPC isn't the fastest way to
call a function on remote server, but it might be one of the easier to
understand. (See http://www.xmlrpc.com/ for details.)

An XML-RPC request looks like this:

  POST /z2/ 1.0
  Content-Type: text/xml
  Content-Length: 170

  <?xml version='1.0'?>
  <methodCall>
    <methodName>test.string_length</methodName>
      <params>
        <param>
          <value><string>foo</string></value>
        </param>
      </params>
  </methodCall>

The response looks like this:

  HTTP/1.1 200 OK
  Content-Length: 122
  Content-Type: text/xml

  <?xml version='1.0'?>
  <methodResponse>
    <params>
      <param>
        <value><int>3</int></value>
      </param>
    </params>
  </methodResponse>

Fredrik Lundh of PythonWare wrote a very nice XML-RPC library for
Python. (See http://www.pythonware.com/products/xmlrpc/ to get a copy.)
Using his code, I could call the above function as:

  >>> import xmlrpclib
  >>> s = xmlrpclib.Server("http://localhost/z2/")
  >>> s.test.string_length("foo")
  3

In other words, XML-RPC lets you treat a remote Zope object almost like a
local Python object. Think of it as a super-simple cousin to CORBA and
DCOM, and you'll get the right idea.

XML-RPC for Zope
----------------

Thanks to all the aforementioned people, you can now use Zope as an XML-RPC
server. It's easy. Here's the source code for 'test.string_length', which
is loaded into Zope as an ordinary external method:

  def string_length(string):
    return len(string)

See what I meant by "easy"? To use XML-RPC for Zope, you'll need to get the
latest version of Zope from CVS and read the release notes on UserLand's
site:

  http://linux.userland.com/stories/storyReader$18

Future Directions
-----------------

Zope XML-RPC still has a few rough edges. If you discover any bugs which
aren't mentioned on the site, or have any ideas for improvement, drop me a
line.

Thank you to all the people who helped out!

Cheers,
Eric