[Welcome] [TitleIndex] [WordIndex

Problem

You want to provide a SOAP interface to your Quixote-based application.

Solution

Toni Alatalo posted example code to the quixote-users list.

methods is a dictionary that maps method name strings to functions that wrap the actual methods on this server. This code uses the SOAPpy library.

def _q_lookup (request, name):
    if name == "soap":
        return soap(request)
    else:
        return xmlrpc(request, rpc_process)


def rpc_process (meth, params):
    print "RPC:", meth, params

    if methods.has_key(meth):
        return methods[meth](params)

    else:
        raise RuntimeError, "Unknown XML-RPC method: %r" % meth


def soap (request): #after quixote.util.xmlrpc
    # Get contents of POST body
    if request.get_method() != 'POST':
        request.response.set_status(405, "Only the POST method is
                                    accepted")
        return "SOAP handlers only accept the POST method. or?"

    length = int(request.environ['CONTENT_LENGTH'])
    data = request.stdin.read(length)

    #print data

    body = SOAPpy.Parser.parseSOAP(data)
    body = SOAPpy.Types.simplify(body)

    #print body

    meth, kwparams = body.items()[0]
    params = kwparams.values()
    if len(params) == 1:
        params = params[0]

    result = rpc_process(meth, params)

    return buildSOAP(result)

If you want to test the SOAP server, you might want to use the following client code, which assumes that the methods defined for the XML-Javascript example (XmlHttpUsingJsolait) are provided by the server:

import SOAPpy
#SOAPpy.Config.Debug=1
server = SOAPpy.SOAPProxy("http://localhost:8080/soap")
print server.get_time()
print server.echo("hello", "world")


CategoryCookbook CategoryQuixote1


2010-09-22 22:14