1. Problem

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

2. 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)


CategoryCookbook