The flamelab XML-RPC Server is a small and lightweight XML-RPC server developed for the usage as a CGI script. Normal webspace providers do not allow the implementation of socket servers or scripts running in an infinite loop. So the only possible solution to run a web service is to implement it as a CGI script which handles the requests when being called. To set up your service with the server you have to register a class witch includes the needed operations.
The module is completely written in Python and follows the XML-RPC specification.
The usage is very simple and intuitive:
#!/usr/bin/python
from xmlrpcserver import *
class Coder(object):
def getScripts(self):
'''get availiable scripts of coder'''
return ['Python', 'PHP', 'ActionScript']
def _privateMethod(self):
#do some stuff in here
server = SimpleXMLRPCCGIServer()
server.registerInstance('coder', Coder())
server.handleRequest()
XML-RPC Server is a Python module and needs a interpreter running. Your webserver must be enabled for executing python scripts. It has been tested under Python 2.2 and 2.3.
For usage, the server imports the xmlrpclib, the sys and the inspect modules which are all part of the Python standard library. No other additional modules are required.
You can download the latest versions of the project here:
The XML-RPC Server comes as a module and can be easily used by importing it into your script with an import statement. To set up the complete service you must provide a class that defines the needed operations.
To set up the server and make it running, you must create an instance, register the desired class and it's operations and make the server handle the request.
server = SimpleXMLRPCCGIServer()
server.registerInstance('coder', Coder())
server.handleRequest()
The server is a normal Python class following the new object oriented style modell. Instances can easily be created without any arguments.
To provide some service functionality you need to register a class with the necessary methods. The class should follow these conventions:
To register the class and it's methods you must create an instance of it and pass it to the server with a string identifying the object.
void registerInstance(String identifier, Object instance)
Handling the request is done automatically when calling the handleRequest method. It interprets the XML-RPC Request, calls the appropirate operation of the registered class or serves an fault and returns an XML-RPC conform response. You do not need to handle any output result in your server script.
void handleRequest()
To query the server you need an XML-RPC client which calls the methods provided by the registered class. The name of the registered operations is build as follows <identifiername>.<operationname> where identifier is the identifierargument set with registerInstance().
The following example shows an call with Python:
#!/usr/bin/python
import xmlrpclib
try:
server = xmlrpclib.Server("http://www.domain.com/service/server.py")
print server.coder.getScripts()
except Exception, e:
print e
In the case of an error, the servers returns faults as recommended by the XML-RPC specification. Handling these faults must be done by the client.
This library is free software; you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information visit http://www.gnu.org/licenses/gpl.txt.
For questions or suggestions drop a line to info@flamelab.de.
0.2: (2005-12-17) initial release
0.2.5: (2005-12-28)