Python SUDS - Interrogating the WSDL for MinOccurs and MaxOccurs values

落花浮王杯 提交于 2019-12-23 04:44:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!