如何在python soap模块zeep中处理complexType参数?
问题描述:
ZEEP文档例如:如何在python soap模块zeep中处理complexType参数?
from zeep import Client
client = Client('http://my-enterprise-endpoint.com')
client.service.submit_order(user_id=1, order={
'number': '1234',
'price': 99,
})
我的使用情况:
我想打电话,需要一个参数 'findCriteria'
示例web服务:
findcriteria = {
'Criteria' : [{
'ColumnName' : 'Closed',
'Value' : 0
},
{
'ColumnName' : 'AssignToQueueID',
'Value' : queueid
},
{
'ColumnName' : 'SupportCallType',
'Value' : 'I'
}
]
}
调用服务:
print clien t.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" />
答
检查用下面的命令您的WSDL: python -mzeep <wsdl>
你会发现在输出服务的细节:ns1:GetCount(FindCriteria:findCriteria)
示例代码基于在上述检查输出上:
find_criteria_type = client.get_type('ns1:findCriteria')
find_criteria = find_criteria_type()
client.service.GetCount(FindCriteria=find_criteria)
如果XML是这样的:在创建OBJ,当你需要通过PARAMS
<soap-env:Body>
<ns1:GetCount>
<ns1:findCriteria>
<ns1:param1>val1</ns1:param1>
<ns1:param2>val2</ns1:param1>
</ns1:findCriteria>
</ns1:GetCount>
</soap-env:Body>
:
find_criteria = find_criteria_type(param1=val1, param2=val2)
答
我有一个类似的问题,我设法解决它,而是帮助你需要一个样本正确的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)
跟着你的建议,但还是没有结果。问题出现在('ns1:findCriteria。这不是有效的类型。谢谢你的努力。 – Peter
可以共享命令输出'python -mzeep | grep GetCount'? –
这个命令不能帮助我,因为我的wsdl是身份验证。我放置了wsdl local,但是它试图包含身份验证背后的其他模式。 – Peter