我認爲泡沫可以幫助你。我給你舉一個例子:
from suds.client import Client
# Web Service Connection
WSDL_URL_PATTERN = "http://{host}:{port}/{service_page}?WSDL"
SERVICE_PAGE = "Example.asmx"
host = host
port = port
username = username
password = password
wsdl_url = WSDL_URL_PATTERN.format(host=host, port=port, service_page=SERVICE_PAGE)
client = Client(wsdl_url, **kwargs)
#Authentication header (optional)
auth = client.factory.create('tns:AuthenticationHeader')
auth.Username = user
auth.Password = passwd
client.set_options(soapheaders=auth)
#My Function Service Call
param1 = "param1"
param2 = "param2"
result = client.service.MyFunction(param1, param2)
for item in result:
print item.myfield
Suds可以有效地創建wsdl中定義的對象,但我無法以xml格式打印它們。 我並不真正瞭解你的「功能服務呼叫」。我需要的是爲所請求的SoapAction定義一個方法,並將結果作爲SOAP請求返回。我只需要找到一種方法來編寫http請求的SOAP部分,我可以自己完成剩下的工作。 – user2282001