2
如何將複雜類型添加到SOAP請求中?wsdl2py ComplexTypes
我正在使用WSDL2py生成的請求,並試圖使用它在*** _ types.py文件(如AccountInfo,用於身份驗證,進入每個請求)中所做的其他TypeDefinitions。然後向它傳遞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()給我們的,但它不公開這些請求需要的類。對於我的生活,我無法弄清楚如何將這個複雜類型正確地放入請求對象,而不會發生錯誤。我一直試圖在** _ types.py文件中實例化定義,並且我一直在嘗試簡單的字典。沒有什麼似乎工作。這是自動生成的定義的樣子,有什麼建議嗎?
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
這似乎現在是'--complexType'標誌(缺少拖尾的's')。 – DuffJ