如何向SOAP请求添加复杂类型?
我正在使用WSDL2py生成的请求,并尝试使用它在*** _ types.py文件中创建的其他TypeDefinition(如AccountInfo,用于身份验证,进入每个请求)。然后将wsdl2py生成的服务器传递给它,我收到此错误:
>>> from AutomotiveDescriptionService6_client import *
>>> from AutomotiveDescriptionService6_types import *
>>> loc = AutomotiveDescriptionService6Locator()
>>> server = loc.getAutomotiveDescriptionService6Port()
>>> request = getDataVersions()
>>> auth = ns0.AccountInfo_Def()
>>> auth._accountName="**"
>>> auth._accountSecret="***"
>>> request._accountInfo = auth
>>> server.getDataVersions(request)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "AutomotiveDescriptionService6_client.py", line 38, in getDataVersions
self.binding.Send(None, None, request, soapaction="", **kw)
File "/usr/lib/pymodules/python2.6/ZSI/client.py", line 246, in Send
sw.serialize(obj, tc)
File "/usr/lib/pymodules/python2.6/ZSI/writer.py", line 117, in serialize
elt = typecode.serialize(self.body, self, pyobj, **kw)
File "/usr/lib/pymodules/python2.6/ZSI/TC.py", line 609, in serialize
pyobj.typecode.serialize(elt, sw, pyobj, **kw)
File "/usr/lib/pymodules/python2.6/ZSI/TCcompound.py", line 275, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/usr/lib/pymodules/python2.6/ZSI/TCcompound.py", line 424, in cb
what.serialize(elem, sw, v, **kw)
File "/usr/lib/pymodules/python2.6/ZSI/TCcompound.py", line 275, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/usr/lib/pymodules/python2.6/ZSI/TCcompound.py", line 437, in cb
sw.Backtrace(elt))
ZSI.EvaluateException: Got None for nillable(False), minOccurs(1) element (urn:description6.kp.chrome.com,accountNumber), <ns1:accountInfo xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:ns1="urn:description6.kp.chrome.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></ns1:accountInfo>
[Element trace: /SOAP-ENV:Body/ns1:DataVersionsRequest]
正如您所看到的,生成请求对象很容易,wsdl2py使用GED()为我们提供这些对象,但它不会公开这些请求所需的类。对于我的生活,我无法弄清楚如何将该复杂类型正确地放入请求对象中,而不会出现该错误。我一直试图在** _ typess.py文件中实例化定义,我一直在尝试简单的dicts。没什么似乎工作。这是自动生成的定义的样子,任何建议?
class ns0:
targetNamespace = "urn:description6.kp.chrome.com"
class AccountInfo_Def(ZSI.TCcompound.ComplexType, TypeDefinition):
schema = "urn:description6.kp.chrome.com"
type = (schema, "AccountInfo")
def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw):
ns = ns0.AccountInfo_Def.schema
TClist = [ZSI.TC.String(pname=(ns,"accountNumber"), aname="_accountNumber", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TC.String(pname=(ns,"accountSecret"), aname="_accountSecret", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), GTD("urn:description6.kp.chrome.com","Locale",lazy=False)(pname=(ns,"locale"), aname="_locale", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded"))]
self.attribute_typecode_dict = attributes or {}
if extend: TClist += ofwhat
if restrict: TClist = ofwhat
ZSI.TCcompound.ComplexType.__init__(self, None, TClist, pname=pname, inorder=0, **kw)
class Holder:
typecode = self
def __init__(self):
# pyclass
self._accountNumber = None
self._accountSecret = None
return
Holder.__name__ = "AccountInfo_Holder"
self.pyclass = Holder
答案 0 :(得分:2)
所以...发现问题是我需要使用--complextypes标志运行wsdl2py。这会在reqeust对象中创建一大堆令人敬畏的方法。像new_XXXXX这样的方法,其中X是该请求所需的复杂类型的名称。