我正在寻找一个 Python SOAP 1.2 客户端,但似乎并不存在。所有现有的客户端要么没有维护,要么仅与 SOAP 1.1 兼容:
- suds
- SOAPpy
- ZSI
我正在寻找一个 Python SOAP 1.2 客户端,但似乎并不存在。所有现有的客户端要么没有维护,要么仅与 SOAP 1.1 兼容:
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()
property
,它从threadlocal
返回一个值到binding.envns
。我还必须重写property
的__getattribute__
和__getitem__
方法,以使该属性与suds一起工作。如果您选择这条路线,最好添加大量注释。 - Lindlofzeep库支持SOAP 1.1和1.2,只要服务的WSDL正确指示即可。
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
:)
)。包装库的一种方法是使用一个名为SWIG(Simplified Wrapper and Interface Generator)的工具。这个工具可以自动地将C/C++库包装成高级语言(例如Python)可用的形式。
我还建议您阅读此PDF文件(从第14页开始),以了解如何在C++中实现gSOAP。它非常有帮助。
使用这个解决方案,您可以利用一个经过良好维护的库、SOAP 1.2和非常不错的性能比率。我相信您会对结果感到非常满意。
我几年前也遇到过非常类似的问题,我通过使用Jython解决了它。
如果Python中没有现有的SOAP 1.2实现,您可能会对Jython感兴趣,它可以无缝地与Java平台集成。这意味着,您可以使用任何现有的SOAP 1.2 Java类,并将其导入到您的Jython程序中。您的Jython程序就是您的Python程序,但您可以导入Java类。
Jython本身包含标准Python编程语言分发中的几乎所有模块,但请确保您的程序不使用任何特殊的非标准Python库。
例如:假设您已经安装了Jython(它是免费和开源的),您的Python程序名为myprog.py,您想要使用Java类CLASSNAME:
1)在myprog.py中插入所需的Java类导入import CLASSNAME
2)运行jython myprog.py