【发布时间】:2013-04-25 14:41:37
【问题描述】:
我尝试了几个小时从 Soap Web 服务接收数据。
这是我的代码:
from suds.client import Client
from suds import WebFault
WSDL_URL = 'gatewaywebservice.asmx?wsdl'
client = Client(WSDL_URL)
checkIfExists = client.factory.create('checkIfExists')
checkIfExists.SessionID = ''
checkIfExists.UserID = 'ttester@email.com'
try:
response = client.service.CustomerService(checkIfExists)
#print response
if response.Error:
print response.Error
else:
pass
except WebFault, e:
print e
print client.last_sent()
print client.last_received()
这是我发送的:
<SOAP-ENV:Envelope xmlns:ns0="asdf" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:CustomerService>
<ns0:CustomerService>
<ns0:SessionID></ns0:SessionID>
<ns0:UserID>ttester@email.com</ns0:UserID>
</ns0:CustomerService>
</ns0:CustomerService>
</ns1:Body>
</SOAP-ENV:Envelope>
这正是网络服务器所期望的:
<?xml version="1.0" encoding="UTF-8"?>
<GATEWAY xmlns="urn:Software-com:Gateway:v7-00">
<CustomerService>
<checkIfExists>
<SessionID/>
<UserID>test</UserID>
</checkIfExists>
</CustomerService>
</GATEWAY>
如何更新我的代码以发送有效请求?
提前致谢
【问题讨论】:
-
您的网络服务器期望的示例肯定不是有效的 SOAP 请求; SUDS 只能发送 WSDL 指定的内容;如果 SUDS 生成的内容有误,则服务器向您发送了错误的 WSDL。
-
IIRC,在您在 url 上初始化客户端后执行
print client,它将显示 suds 为您提供的 Web 服务界面。它可能与您的想法略有不同。我记得我必须这样做才能让它正常工作一次:suds 只等待两个叶子对象,我在其中提供一个包含两个叶子对象的对象作为输入。