wsdl2py 复杂类型 [英] wsdl2py ComplexTypes
问题描述
如何向 SOAP 请求添加复杂类型?
我正在使用 WSDL2py 生成的请求,并尝试使用它在 ***_types.py 文件中创建的其他类型定义(如 AccountInfo,用于身份验证,进入每个请求).然后将它传递给 wsdl2py 生成的服务器,我收到此错误:
<预><代码>>>>从 AutomotiveDescriptionService6_client 导入 *>>>从 AutomotiveDescriptionService6_types 导入 *>>>loc = AutomotiveDescriptionService6Locator()>>>服务器 = loc.getAutomotiveDescriptionService6Port()>>>请求 = getDataVersions()>>>auth = ns0.AccountInfo_Def()>>>auth._accountName="**">>>auth._accountSecret="***">>>request._accountInfo = auth>>>server.getDataVersions(请求)回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中getDataVersions 中的文件AutomotiveDescriptionService6_client.py",第 38 行self.binding.Send(None, None, request, soapaction="", **kw)文件/usr/lib/pymodules/python2.6/ZSI/client.py",第246行,发送sw.serialize(obj, tc)文件/usr/lib/pymodules/python2.6/ZSI/writer.py",第117行,序列化elt = typecode.serialize(self.body, self, pyobj, **kw)文件/usr/lib/pymodules/python2.6/ZSI/TC.py",第609行,序列化pyobj.typecode.serialize(elt, sw, pyobj, **kw)文件/usr/lib/pymodules/python2.6/ZSI/TCcompound.py",第275行,序列化self.cb(elt, sw, pyobj, name=name, **kw)文件/usr/lib/pymodules/python2.6/ZSI/TCcompound.py",第424行,cbwhat.serialize(elem, sw, v, **kw)文件/usr/lib/pymodules/python2.6/ZSI/TCcompound.py",第275行,序列化self.cb(elt, sw, pyobj, name=name, **kw)文件/usr/lib/pymodules/python2.6/ZSI/TCcompound.py",第437行,cbsw.Backtrace(elt))ZSI.EvaluateException:对于 nillable(False)、minOccurs(1) 元素 (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>[元素跟踪:/SOAP-ENV:Body/ns1:DataVersionsRequest]如您所见,生成请求对象很容易,wsdl2py 使用 GED() 为我们提供这些对象,但它不会公开这些请求所需的类.在我的一生中,我无法弄清楚如何将这种复杂类型正确地放入请求对象中,而不会出现该错误.我一直在尝试实例化 **_types.py 文件中的定义,而且我一直在尝试简单的字典.似乎没有任何效果.这是自动生成的定义的样子,有什么建议吗?
类 ns0:targetNamespace = "urn:description6.kp.chrome.com"类 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.schemaTClist = [ZSI.TC.String(pname=(ns,"accountNumber"), aname="_accountNumber", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoding=kw.get("encoded")), ZSI.TC.String(pname=(ns,"accountSecret"), aname="_accountSecret", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoding=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 = 属性或 {}如果扩展:TClist += ofwhat如果限制:TClist = ofwhatZSI.TCcompound.ComplexType.__init__(self, None, TClist, pname=pname, inorder=0, **kw)班级持有人:类型代码 = 自我def __init__(self):#pyclassself._accountNumber = 无self._accountSecret = 无返回Holder.__name__ = "AccountInfo_Holder"self.pyclass = 持有人
所以...发现问题是我需要使用 --complextypes 标志运行 wsdl2py.这在内部创建了一系列很棒的方法请求对象.new_XXXXX 之类的方法,其中 X 是该请求所需的复杂类型的名称.
How do I add complex types to a SOAP request?
I'm using WSDL2py generated requests, and trying to use the other TypeDefinitions that it made in the ***_types.py file (like AccountInfo, for authentication, that goes into every request). Then passing it the wsdl2py generated server, and I'm getting this error:
>>> 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]
As you can see, it's easy to generate request objects, wsdl2py uses GED() to give us those, but it DOESN'T expose the classes that those requests need. For the life of me, I can't figure out how the hell to get that complex type properly into the request object, without getting that error. I've been trying to instantiate the definition in the **_types.py file, and I've been trying just plain dicts. NOTHING seems to work. Here's what the auto-generated definition looks like, any suggestions?
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
So... found out that the problem is I needed to run wsdl2py with the --complextypes flag.This creates a whole slew of awesome methods inside of the reqeust object. methods like new_XXXXX where X is the name of the complex type that's required by that request.
这篇关于wsdl2py 复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!