Search code examples
pythonweb-servicessoappython-3.6spyne

Spyne - How do I accept key value pairs in a SOAP endpoint?


I'm trying to build a SOAP service and I want to pass something like below to an endpoint.

    <payload>
        <initiation_date>2019-05-17T00:00:00.000</initiation_date>
        <facility_num>123</facility_num>
        <order_num>123</order_num>
    </payload>  

What I'm trying to achieve is get is a dict in my endpoint.

My endpoint looks like this:

class SoapService(ServiceBase):

    @rpc(Unicode, Unicode, Unicode, Array(Unicode), _returns=String)
        def soap_service(self, email, password, action, payload):

What I need in my soap_service endpoint is something like:

payload = {
              'initiation_date': '2019-05-17T00:00:00.000',
              'facility_num': '123',
              'order_num': '123'
          }

How do I achieve this?

I'd really appreciate the help!


Solution

  • Figured, I just had to change my payload type in the decorator to AnyDict.

    This works:

    @rpc(Unicode, Unicode, Unicode, AnyDict, _returns=String)
            def soap_service(self, email, password, action, payload):
    

    Thanks!