Python 中使用 ZSI 的 Web 服务客户端 - “无类结构没有获取字典”

发布于 2024-08-06 09:03:34 字数 2715 浏览 2 评论 0原文

我正在尝试使用 ZSI 使用 Python 编写一个示例客户端来实现简单的 Web 服务。 Web 服务 WSDL 如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test" targetNamespace="http://www.example.org/test/">
  <wsdl:message name="NewOperationRequest">
    <wsdl:part name="NewOperationRequest" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="NewOperationResponse">
    <wsdl:part name="NewOperationResponse" type="xsd:string"/>
  </wsdl:message>
  <wsdl:portType name="test">
    <wsdl:operation name="NewOperation">
      <wsdl:input message="tns:NewOperationRequest"/>
      <wsdl:output message="tns:NewOperationResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="testSOAP" type="tns:test">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="NewOperation">
      <soap:operation soapAction="http://www.example.org/test/NewOperation"/>
      <wsdl:input>
        <soap:body namespace="http://www.example.org/test/" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body namespace="http://www.example.org/test/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="test">
    <wsdl:port binding="tns:testSOAP" name="testSOAP">
      <soap:address location="http://localhost/test"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

每次运行以下代码时:

from ZSI.ServiceProxy import ServiceProxy
service = ServiceProxy('test.wsdl')
service.NewOperation('test')

我收到:

(...)
/var/lib/python-support/python2.5/ZSI/TCcompound.pyc in cb(self, elt, sw, pyobj, name, **kw)
    345             f = lambda attr: pyobj.get(attr)                                        
    346             if TypeCode.typechecks and type(d) != types.DictType:                   
--> 347                 raise TypeError("Classless struct didn't get dictionary")           
    348                                                                                     
    349         indx, lenofwhat = 0, len(self.ofwhat)                                       

TypeError: Classless struct didn't get dictionary

我在 Google 中搜索了此错误,发现了几篇描述类似问题但没有答案的帖子。你知道这里错了吗? WSDL 中是否存在错误、我是否遗漏了代码中的某些内容或者 ZSI 中存在错误?

预先感谢您的帮助:-)

I am trying to write a sample client in Python using ZSI for a simple Web Service. The Web Service WSDL is following:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test" targetNamespace="http://www.example.org/test/">
  <wsdl:message name="NewOperationRequest">
    <wsdl:part name="NewOperationRequest" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="NewOperationResponse">
    <wsdl:part name="NewOperationResponse" type="xsd:string"/>
  </wsdl:message>
  <wsdl:portType name="test">
    <wsdl:operation name="NewOperation">
      <wsdl:input message="tns:NewOperationRequest"/>
      <wsdl:output message="tns:NewOperationResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="testSOAP" type="tns:test">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="NewOperation">
      <soap:operation soapAction="http://www.example.org/test/NewOperation"/>
      <wsdl:input>
        <soap:body namespace="http://www.example.org/test/" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body namespace="http://www.example.org/test/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="test">
    <wsdl:port binding="tns:testSOAP" name="testSOAP">
      <soap:address location="http://localhost/test"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Every time I run following code:

from ZSI.ServiceProxy import ServiceProxy
service = ServiceProxy('test.wsdl')
service.NewOperation('test')

I receive:

(...)
/var/lib/python-support/python2.5/ZSI/TCcompound.pyc in cb(self, elt, sw, pyobj, name, **kw)
    345             f = lambda attr: pyobj.get(attr)                                        
    346             if TypeCode.typechecks and type(d) != types.DictType:                   
--> 347                 raise TypeError("Classless struct didn't get dictionary")           
    348                                                                                     
    349         indx, lenofwhat = 0, len(self.ofwhat)                                       

TypeError: Classless struct didn't get dictionary

I have searched Google for this error and I found couple posts describing similar problem but with no answer. Do you know was is wrong here? Is there an error in the WSDL, do I miss something in the code or there is a bug in ZSI?

Thank you in advance for you help :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风和你 2024-08-13 09:03:34

最后,我找到了解决方案。

我应该这样运行:

from ZSI.ServiceProxy import ServiceProxy
service = ServiceProxy('test.wsdl')
service.NewOperation(NewOperationRequest='test')

问题的原因是参数名称丢失(原文如此!) - 愚蠢的错误;-)

Finally, I have found the solution.

I should run like this:

from ZSI.ServiceProxy import ServiceProxy
service = ServiceProxy('test.wsdl')
service.NewOperation(NewOperationRequest='test')

The reason of the problem was that the name of the parameter was missing (sic!) - silly error ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文