python - 如何处理pythonsoap模块zeep中的complexType参数?

标签 python web-services soap

Zeep 文档示例:

from zeep import Client

client = Client('http://my-enterprise-endpoint.com')
client.service.submit_order(user_id=1, order={
    'number': '1234',
    'price': 99,
})

我的用例:

我想调用需要参数“findCriteria”的网络服务

示例:

findcriteria =  {
        'Criteria' : [{
                        'ColumnName' : 'Closed',
                        'Value' : 0
                },
                {
                        'ColumnName' : 'AssignToQueueID',
                        'Value' : queueid
                },
                {
                        'ColumnName' : 'SupportCallType',
                        'Value' : 'I'
                }
                ]
        }

调用服务:

打印 client.service.GetCount(findCriteria = findcriteria)

这是创建的 XML:

<soap-env:Body>
    <ns1:GetCount>
      <ns1:findCriteria/>
    </ns1:GetCount>
  </soap-env:Body>
</soap-env:Envelope>

问题:

虽然服务返回计数,但不应用条件。

当我向服务提供原始 XML 负载时,结果正常。

问题出在 <ns1:findCriteria/>部分。

应该为每一列创建一个 Criteria 元素。

WSDL 上 grep GetCount 的结果:

<s:element name="GetCount">
      <s:element name="GetCountResponse">
            <s:element minOccurs="1" maxOccurs="1" name="GetCountResult" type="s:int" />
  <wsdl:message name="GetCountSoapIn">
    <wsdl:part name="parameters" element="tns:GetCount" />
  <wsdl:message name="GetCountSoapOut">
    <wsdl:part name="parameters" element="tns:GetCountResponse" />
    <wsdl:operation name="GetCount">
      <wsdl:input message="tns:GetCountSoapIn" />
      <wsdl:output message="tns:GetCountSoapOut" />
    <wsdl:operation name="GetCount">
      <soap:operation soapAction="http://<server>/webservices/SupportCall/GetCount" style="document" />
    <wsdl:operation name="GetCount">
      <soap12:operation soapAction="http://<server>/webservices/SupportCall/GetCount" style="document" />

最佳答案

我遇到了类似的问题,并且设法解决了它,但为了帮助您,我需要一个正确的 XML 示例(它应该是什么样子),或者至少需要一个使用 SoapUI 生成的默认请求。

与此同时,也许下面的代码可以帮助您: 这里复杂的参数是凭据,它由 2 个登录项组成:登录名和域。

<soap-env:Envelope xmlns:ns1="http://xml.kamsoft.pl/ws/kaas/login_types" 
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns1:login>
      <ns1:credentials>
        <ns1:item>
          <ns1:name>login</ns1:name>
          <ns1:value>
             <ns1:stringValue>login_here</ns1:stringValue>
          </ns1:value>
        </ns1:item>
        <ns1:item>
           <ns1:name>domain</ns1:name>
           <ns1:value>
             <ns1:stringValue>domain_here</ns1:stringValue>
           </ns1:value>
        </ns1:item>
      </ns1:credentials>
      <ns1:password>password_here</ns1:password>
    </ns1:login>
  </soap-env:Body>
</soap-env:Envelope>

下面是生成此 XML 的代码:

domain = "domain_here"
login = "login_here"
password = "password_here"
credentials = {"item": [{"name": "login", 'value': {"stringValue": login}},
                        {"name": "domain", 'value': {"stringValue": domain}}]}
client.service.login(credentials=credentials, password=password)

关于python - 如何处理pythonsoap模块zeep中的complexType参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38539568/

相关文章:

python - 在 python-2.7 的 sqlite3 中的嵌套循环中使用多个游标

python - 如何使用 Sympy 自动简化二值有限域上的表达式?

python - 无法在 Python 中导入 Skype4Py

java - Soap 1.2 支持 jaxws 中的 text/xml 内容类型

python - 在python上进行ARP请求

asp.net - App.Config 和 Web.Config 之间的区别?

c# - 使用 XmlSerializerFormat 时 WCF 服务请求为空

web-services - Web 服务身份验证 - 最佳实践?

c# - 具有 WS-Security 的 WCF 客户端

web-services - Axis 自底向上 Web 服务 IWAB0489E 错误