Map Python dict to a WSDL complex type

820 Views Asked by At

I have a SOAP service method that wants to receive an argument of dict type.

Currently i am working around this using:

class KeyValue(ComplexModel):
    key = Mandatory.Unicode
    value = Mandatory.Unicode

And:

class ASoapService(ServiceBase):

    @rpc(KeyValue.customize(min_occurs=0, max_occurs='unbounded'))
    def a_method(ctx, a_dict):
        # here a_dict is a list of KeyValue instances
        # convert it to a real dict
        a_dict = {item.key: item.value for item in a_dict}
        ...

The means that using a JSON client to this service i would pass:

{"a_method":
  {"a_dict": [
    {"key": "key1", "value": "value1"},
    {"key": "key2", "value": "value2"},
    ...
  ]}
}

which is ugly, imo.

Is there a better way to map a Python dictionary to a WSDL type, to be able to pass:

{"a_method":
  {"a_dict": {
    "key1": "value1",
    "key2": "value2",
    ...
  }
}
0

There are 0 best solutions below