XML-RPC for Zope

Eric Kidd eric at userland.com
Thu Jun 17 23:25:29 CEST 1999


Hello! Dave Winer of UserLand software (my boss) has generously allowed me
to add XML-RPC support to Zope. Since I'm lazy--and Fredrik Lundh has
already written a wonderful XML-RPC module for Python--my code simply
hooks Fredrik's routines into Zope's server architecture. The hard work
was done by the following people:

 * Jim Fulton of Digital Creations, who added XML-RPC hooks to ZPublisher
   and answering my stupid questions.
 * Fredrik Lundh of PythonWare, who wrote an 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 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
----------------

Writing XML-RPC methods is just as easy, thanks to Zope. Simply load a
Python function as an External Method, and you're ready to go:

  def string_length(string):
    return len(string)

Easy, huh? 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 Kidd
UserLand Software




More information about the Python-list mailing list