首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wsdl2py ComplexTypes

wsdl2py ComplexTypes
EN

Stack Overflow用户
提问于 2010-03-05 04:55:01
回答 1查看 2.3K关注 0票数 2

如何将复杂类型添加到SOAP请求?

我正在使用WSDL2py生成的请求,并尝试使用它在***_types.py文件中创建的另一个TypeDefinitions (如AccountInfo,用于身份验证,进入每个请求)。然后将它传递给wsdl2py生成的服务器,我得到了这个错误:

代码语言:javascript
复制
>>> 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文件中的定义,并且一直在尝试普通的字典。似乎什么都不起作用。下面是自动生成的定义,有什么建议吗?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2010-03-05 05:36:28

所以..。我发现问题是我需要用--复杂类型来运行wsdl2py -- flag.This在reqeust对象中创建了一大堆很棒的方法。方法,如new_XXXXX,其中X是该请求所需的复杂类型的名称。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2382650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档