问题
I would like to interrogate a WSDL using SUDS to get the parameters and attributes of a web service. I'm pretty much down to this one last thing. How do I interrogate the service to find the minOccurs and maxOccurs values of the parameters?
I see there's a property in the suds.xsd.sxbase object called required, but, assuming my starting point is the client object, I don't see path to get to it.
http://jortel.fedorapeople.org/suds/doc/suds.xsd.sxbase-pysrc.html#SchemaObject.required
client = Client(endpoint, username=username, password=password)
client.service[0][method]
How can I find out if a parameter is bound?
Thanks!
回答1:
you can query the factory resolver for the method, and use the children() method to see its parameters.
example, for this method I have my wsdl:
<complexType name="AddAuthorizationRoleRequestType">
<sequence>
<element name="_this" type="vim25:ManagedObjectReference" />
<element name="name" type="xsd:string" />
<element name="privIds" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
I can get the attributes via:
>>> a=client.factory.resolver.find("ns0:AddAuthorizationRoleRequestType")
>>> priv_el=a.children()[2][0]
<Element:0x107591a10 name="privIds" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
>>> priv_el = a.children()[2][0]
>>> priv_el.max
unbounded
>>> priv_el.min
0
not very elegant, but it works
来源:https://stackoverflow.com/questions/9500626/python-suds-interrogating-the-wsdl-for-minoccurs-and-maxoccurs-values