Thought this might be interesting to someone, as it took me digging
through the pysimplesoap code to figure out. So I'll record it here
for posterity.
In web2py, I needed a soap service that can have one to many sets of a
a particular element. This caused some issues, as there's not really a
convention documented for supporting multiple elements posted in,
without explicitly defining all of them.
what I found, was putting a dict in a list, you could get this (taken
from the "unmarshall" section of the simplexml code, since the
pysimplesoap does this:
args = method.children().unmarshall(args_types)
# types is a dict of {tag name: convertion function}
# example: types={'p': {'a': int,'b': int}, 'c': [{'d':str}]}
# expected xml: <p><a>1</a><b>2</b></p><c><d>hola</d><d>chau</d>
# returned value: {'p': {'a':1,'b':2}, `'c':[{'d':'hola'},
{'d':'chau'}]}
Notice in there, that by putting the {'d':str} object in a list, even
a single element list, it makes it able to be repeated, over and over
again. No idea how to set a limit on repetitions, or how this would
react to simply not including a value (is a zero to many, or one to
many?) but I'm trying it out now. Here's the completed decorator and
func definition:
@service.soap('methodName',returns={'result':bool},
args={'data':[{'elemName':str, 'elemValue':str}]})
def mymethod(data):
"""
Does nothing right now.
"""
# the var data is filled with a list of dicts. Each dict has two
elements,
# "elemName" and "elemValue", both strings. Can iterate over this,
and pull
# out any data required.
return True
So it currently doesn't do anything yet, and the design is bad since I
was handed a wsdl and told "make that work", but here's outstanding
questions I have on pysimplesoap/web2py soap stuff:
1) It doesn't look like there's currently any way to say "int between
x and y", just that it's an int. Since it's auto generating the wsdl,
that seems important...
2) Same as above goes for data from a particular set. I can validate
this in the code of the service, but I really have no clue how to get
that into the wsdl.
3) How do I get this to throw a specific soap fault, when there's an
error?
4) Can I make a particular value optional (0-1 repetitions) or a range
of repetitions? (5-100, 1-4, etc) or is this also something that needs
to go in the python code, and it just can't make it into the wsdl
right now?
5) What are my options with "complex types" or "custom types"?
Supported, unsupported? (http://oreilly.com/catalog/javasoap/chapter/
ch05.html)
6) Still playing around with how to change my soap response up.
Dealing much more with the simplexml.py code than I would have
thought, as the soapdispatcher.py code is very simple (good thing!)