SOAP 1.2 python 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2370573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SOAP 1.2 python client
提问by Philippe F
I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1:
我正在寻找一个 python SOAP 1.2 客户端,但它似乎不存在。所有现有的客户端要么不维护,要么只与 SOAP 1.1 兼容:
- suds
- SOAPpy
- ZSI
- 泡沫
- 肥皂剧
- ZSI
采纳答案by Phil Rykoff
The zeeplibrary supports both SOAP 1.1 and 1.2 as long as the service's WSDL properly indicates it.
该ZEEP库支持SOAP 1.1和1.2,只要服务的WSDL正确显示它。
WSF/Python is supporting SOAP 1.2.
WSF/Python 支持 SOAP 1.2。
INTRODUCTION
WSF/Python is the Python language extension to WSO2 WSF/C [http://www.wso2.org/projects/wsf/c]. This version enables you to consume/provide Web Services both with REST and SOAP.
- Support for REST
- Support for SOAP 1.1
- Support for SOAP 1.2
For downloading, you don't have to register. Just click "submit" at the very bottom.
Samples can be found within the downloaded archive, eg:
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
介绍
WSF/Python 是 WSO2 WSF/C [ http://www.wso2.org/projects/wsf/c]的 Python 语言扩展。此版本使您能够使用/提供带有 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
回答by Keith Gaughan
Even though this question has an accepted answer, there's a few notes I'd like regarding suds.
尽管这个问题有一个公认的答案,但我还是想提出一些关于泡沫的注意事项。
I'm currently writing some code for interfacing with .tel community hosting for work and I needed a Python SOAP library, and suds was pretty much ideal except for its lack of support for SOAP 1.2.
我目前正在编写一些代码来与 .tel 社区托管进行工作,我需要一个 Python SOAP 库,而 suds 非常理想,除了缺乏对 SOAP 1.2 的支持。
I managed to hack around the problem as for my purposes, SOAP 1.1 and SOAP 1.2 share enough in common that I was able to simply patch suds to use the SOAP 1.2 envelope namespace. I outlined what I did in this gist: https://gist.github.com/858851
为了我的目的,我设法解决了这个问题,SOAP 1.1 和 SOAP 1.2 有足够的共同点,我能够简单地修补 suds 以使用 SOAP 1.2 信封命名空间。我概述了我在这个要点中所做的事情:https: //gist.github.com/858851
As it's worth reproducing here, here's the code:
由于值得在这里重现,这里是代码:
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()
If I've time, I'm planning on submitting a patch to suds to allow the version of SOAP to be used to be specified, and to add enough missing functionality to make it useful.
如果我有时间,我计划向 suds 提交补丁以允许指定要使用的 SOAP 版本,并添加足够多的缺失功能以使其有用。
回答by Kyle Rozendo
If you are really wanting to use SOAP 1.2 even though it is not used as a standard as yet, I reckon I can post an answer that requires some work (all for the greater good :)
).
如果您真的想使用 SOAP 1.2,即使它还没有用作标准,我想我可以发布一个需要一些工作的答案(一切都是为了更大的利益:)
)。
I recommend that you use gSOAP:
我建议您使用gSOAP:
gSOAP - a easy-use, cross-platform toolkit for C/C++ lovers to develop XML-based Web services and XML parsers. Although it is well-known as a Web service development toolkit and has been proved its good performance, it can also be used to create high-performance XML parsers, serializers and deserializers from XML schemas or C/C++ structs/classes. My experimental results demonstrate that the XML parsers generated using gSOAP toolkit run several times faster than xerces-c parsers in either DOM or SAX mode.
gSOAP - 一个易于使用的跨平台工具包,供 C/C++ 爱好者开发基于 XML 的 Web 服务和 XML 解析器。尽管它作为 Web 服务开发工具包广为人知并已被证明具有良好的性能,但它也可用于从 XML 模式或 C/C++ 结构/类创建高性能 XML 解析器、序列化器和反序列化器。我的实验结果表明,在 DOM 或 SAX 模式下,使用 gSOAP 工具包生成的 XML 解析器的运行速度比 xerces-c 解析器快几倍。
Now, I wish it were that easy. Due to gSOAP being a C++ library, you are going to have to wrap it to be able to use it in Python.
现在,我希望事情就这么简单。由于 gSOAP 是一个 C++ 库,您必须将它包装起来才能在 Python 中使用它。
One way of wrapping the library is to use a tool by the name of SWIG(Simplified Wrapper and Interface Generator). This tool automatically wraps C/C++ libraries for use in high level languages, for example (you guessed it) Python.
包装库的一种方法是使用名为SWIG(简化包装器和接口生成器)的工具。此工具会自动包装 C/C++ 库以用于高级语言,例如(您猜对了)Python。
I also recommend you read this PDF file (from page 14)on implementing gSOAP with C++. It is very helpful.
我还建议您阅读有关使用 C++ 实现 gSOAP 的PDF 文件(从第 14 页开始)。这是非常有帮助的。
Using this solution, you can utilize a well looked after library, SOAP 1.2 and a very nice performance ratio. I think you will be quite happy with the results.
使用此解决方案,您可以利用一个精心维护的库、SOAP 1.2 和非常好的性能比。我想你会对结果很满意。
回答by psihodelia
I have had the very similar problem some years ago and I have solved it by using Jython.
几年前我遇到了非常相似的问题,我使用 Jython 解决了它。
If there is no existed implementation of SOAP 1.2 for Python, you may be interested in Jython, which seamlessly integrates you with the Java platform. It means, you can use any of the existed SOAP 1.2 Java classesand just import it into your Jython program. Your Jython program is just your Python program, but you can import Java classes.
如果不存在用于 Python 的 SOAP 1.2 实现,您可能会对Jython感兴趣,它将您与 Java 平台无缝集成。这意味着,您可以使用任何现有的SOAP 1.2 Java 类并将其导入您的 Jython 程序。您的 Jython 程序只是您的 Python 程序,但您可以导入 Java 类。
Jython itself includes almost all of the modules in the standard Python programming language distribution, but be sure that your program does not use any special non-standard Python library.
Jython 本身包含标准 Python 编程语言发行版中的几乎所有模块,但请确保您的程序不使用任何特殊的非标准 Python 库。
Example: say, you have Jython installed (it is free and Open Source) and your Python program is called myprog.py and you want use Java class CLASSNAME:
示例:假设您安装了 Jython(它是免费且开源的)并且您的 Python 程序名为 myprog.py,并且您想要使用 Java 类 CLASSNAME:
1) import required Java class inserting import CLASSNAME
into your myprog.py
2) run jython myprog.py
1) 将所需的 Java 类插入import CLASSNAME
到 myprog.py 中
2) 运行jython myprog.py