Kei*_*han 11
即使这个问题有一个公认的答案,但我还是有一些关于肥皂水的说明.
我目前正在编写一些与.tel社区托管工作接口的代码,我需要一个Python SOAP库,除了缺乏对SOAP 1.2的支持外,suds非常理想.
为了我的目的,我设法解决了这个问题,SOAP 1.1和SOAP 1.2共享足够共同,我能够简单地修补suds以使用SOAP 1.2信封名称空间.我概述了我在这个要点中所做的事情:https://gist.github.com/858851
因为它值得再现,这里是代码:
from suds.client import Client
from suds.bindings import binding
import logging
USERNAME = 'username'
PASSWORD = 'password'
# Just for debugging purposes.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Telnic's SOAP server expects a SOAP 1.2 envelope, not a SOAP 1.1 envelope
# and will complain if this hack isn't done.
binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('client.wsdl',
username=USERNAME,
password=PASSWORD,
headers={'Content-Type': 'application/soap+xml'})
# This will now work just fine.
client.service.someRandomMethod()
Run Code Online (Sandbox Code Playgroud)
如果我有时间,我打算提交一个suds补丁,以允许指定SOAP版本,并添加足够的缺失功能以使其有用.
只要服务的WSDL正确指示它,zeep库就支持SOAP 1.1和1.2.
WSF/Python支持SOAP 1.2.
介绍
WSF/Python是WSO2 WSF/C的Python语言扩展[ http://www.wso2.org/projects/wsf/c].此版本使您可以使用REST和SOAP来使用/提供Web服务.
- 支持REST
- 支持SOAP 1.1
- 支持SOAP 1.2
要下载,您无需注册.只需点击最底部的"提交"即可.
样本可以在下载的档案中找到,例如:
LOG_DIR = '/tmp/'
LOG_LEVEL = 4
WSFC_HOME = '/opt/wso2/wsf_c'
END_POINT = 'http://localhost:9090/axis2/services/echo/echoString'
if __name__ == '__main__':
message = """
<ns1:echoString xmlns:ns1="http://ws.apache.org/axis2/services/echo">
<text>Hello World!</text>
</ns1:echoString>
"""
try:
client = wso2.wsf.WSClient({
'to':END_POINT,
'WSF_LOG_DIR':LOG_DIR,
'WSF_LOG_LEVEL':LOG_LEVEL,
'WSFC_HOME':WSFC_HOME,
})
print 'Sending: ' + message
response = client.request(message)
if response is not None:
print 'Respose: ' + response + '\n'
else:
print 'Error occurred!'
except wso2.wsf.WSFault, e:
print 'Exception occurred:'
print e
Run Code Online (Sandbox Code Playgroud)
如果你真的想要使用SOAP 1.2,即使它还没有被用作标准,我想我可以发布一个需要一些工作的答案(一切都是为了更大的好处:)).
我建议你使用gSOAP:
gSOAP - 一个易于使用的跨平台工具包,供C/C++爱好者开发基于XML的Web服务和XML解析器.虽然它作为Web服务开发工具包而闻名,并且已被证明其良好的性能,但它也可用于从XML模式或C/C++结构/类创建高性能XML解析器,序列化器和反序列化器.我的实验结果表明,使用gSOAP工具包生成的XML解析器运行速度比DOM或SAX模式下的xerces-c解析器快几倍.
现在,我希望这很容易.由于gSOAP是一个C++库,因此您必须将其包装起来才能在Python中使用它.
包装库的一种方法是使用名为SWIG(Simplified Wrapper和Interface Generator)的工具.此工具自动包装C/C++库以用于高级语言,例如(您猜对了)Python.
我还建议您阅读此PDF文件(第14页),了解如何使用C++实现gSOAP.这非常有帮助.
使用此解决方案,您可以使用经过良好检查的库,SOAP 1.2和非常好的性能比.我想你会对结果很满意.