Simple SOAP Servlet

Simple SOAP Servlet

from WebKit.RPCServlet import RPCServlet
import SOAPpy

class SOAPServlet(RPCServlet):
    def __init__(self):
        RPCServlet.__init__(self)
        self.encoding = 'UTF-8'

    def respondToPost(self, transaction):
        rawData = transaction.request().rawInput(rewind=True).read()
        p, header, body, attrs = SOAPpy.parseSOAPRPC(rawData, 1, 1, 1)
        methodName, args, kwargs, ns = p._name, p._aslist, p._asdict, p._ns

        result = self.call(methodName, *args())

        result = {"Result": result}
        resp = SOAPpy.buildSOAP(kw={'%sResponse' % methodName: result}, encoding=self.encoding)

        self.sendOK('text/xml', resp, transaction, self.encoding)

Servlet Example

class soap(SOAPServlet):
    def exposedMethods(self): return ['hello']

    def hello(self, name):
        return "Hello %s" % name

Working example

>>> import SOAPpy
>>> server = SOAPpy.SOAPProxy("http://localhost/soap")
>>> print server.hello('whitekid')
Hello whitekid
>>>

-- whitekid