基于wsdl创建pythonsoap服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14059142/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 10:20:16  来源:igfitidea点击:

Create python soap server based on wsdl

pythonsoapwsdl

提问by inversus

I have an wsdl file describing the communication server-client on a Java product. I'm implementing a new server based on Python that will implement the same services.

我有一个 wsdl 文件,描述了 Java 产品上的通信服务器-客户端。我正在实现一个基于 Python 的新服务器,它将实现相同的服务。

Do you know of any method to create the Python server code based on the wsdl, that does not requires me to write all of the complextypes involved?

你知道有什么方法可以基于 wsdl 创建 Python 服务器代码,不需要我编写所有涉及的复杂类型吗?

Also, what Api do you recommend?

另外,你推荐什么Api?

采纳答案by Bogdan

When it comes to SOAP support, Python unfortunately no longer is with "batteries included". The support on client side is acceptable but on server side you are basically on your own.

当谈到 SOAP 支持时,不幸的是 Python 不再带有“包含电池”。客户端的支持是可以接受的,但在服务器端,您基本上是靠自己的。

You might want to look at the following for starters:

对于初学者,您可能需要查看以下内容:

http://wiki.python.org/moin/WebServices

http://wiki.python.org/moin/WebServices

http://pywebsvcs.sourceforge.net/

http://pywebsvcs.sourceforge.net/

http://doughellmann.com/2009/09/01/evaluating-tools-for-developing-with-soap-in-python.html

http://doughellmann.com/2009/09/01/evaluating-tools-for-developing-with-soap-in-python.html

If you really want to go on this route, it seems that ZSIis the tool to use, although I have my doubts that it will work with the latest 2.x Python distribution.

如果你真的想走这条路,似乎ZSI是可以使用的工具,尽管我怀疑它是否适用于最新的 2.x Python 发行版。

Using Python 2.6.6, I tried to use ZSI 2.0 to build a web service starting from the WSDL. Got some "module has been deprecated" warnings when generating the code with wsdl2pyand wsdl2dispatch, had to separately install PyXMLand hack my sys.pathjust to make it resolve first or else I got "module ext.reader does not exist" then only to end up with a disappointing "ZSI:EvaluateException Got None for nillable(False), minOccurs(1) element" error on a basic "Hello world!" WS with a required element.

使用 Python 2.6.6,我尝试使用 ZSI 2.0 从 WSDL 开始构建 Web 服务。使用wsdl2pyand生成代码时收到一些“模块已弃用”警告wsdl2dispatch,必须单独安装PyXML并破解我的sys.path只是为了让它首先解决,否则我会得到“模块 ext.reader 不存在”然后只得到一个令人失望的“ZSI:EvaluateException Got None for nillable(False), minOccurs(1) 元素”基本“Hello world!”错误 带有必需元素的 WS。

Switched to ZSI 2.1_a1 which no longer needs PyXML and wsdl2pydoes it all (what wsdl2dispatchdid for 2.0) but still ended up in a dead end with "ZSI:EvaluateException Got None for nillable(False), minOccurs(1) element" errors.

切换到 ZSI 2.1_a1,它不再需要 PyXML 并wsdl2py完成所有操作(wsdl2dispatch对 2.0 做了什么),但仍然以“ZSI:EvaluateException Got None for nillable(False), minOccurs(1) element”错误告终。

The experience wasn't very fun but it was enough for me to form an opinion about what Python has to offer for SOAP web services... which ain't much (and that was just for basic web services nothing fancy like WS-* specs). YMMV!

体验不是很有趣,但足以让我对 Python 必须为 SOAP Web 服务提供的内容形成意见......这并不多(而且这只是针对基本的 Web 服务,没有像WS-*这样的花哨的东西)规格)。天啊!

EDIT :I recently bumped into this SO question, and although oriented versus a client solution, it does also mention a few libraries for building SOAP services.

编辑:我最近遇到了这个 SO 问题,虽然面向客户端解决方案,但它也提到了一些用于构建 SOAP 服务的库。

回答by Francisco Meza

This question has not received enough attention.

The currently accepted answer is good, but its answer is 'no'. Is there really no reasonably maintained and general solution?

这个问题没有得到足够的重视。

当前接受的答案是好的,但它的答案是“否”。真的没有合理维护和通用的解决方案吗?

Unfortunately, I don't think the negative answer is due to lack of attention to the question. There really is no support for WSDL in python. If you want to avoid the complexities of building your own soap envelope from scratch the only thing I can recommend you is building a sample envelope using any of the many soap webservices tools (soapui for instance) and then use it as a template string (I know, horrible) in your python code

不幸的是,我不认为否定的答案是由于缺乏对问题的关注。python中确实不支持WSDL。如果您想避免从头开始构建自己的soap信封的复杂性,我唯一建议您使用许多soap webservices工具(例如soapui)中的任何一个构建示例信封,然后将其用作模板字符串(我知道,可怕)在你的 python 代码中

UPDATEyou could use spyne. It's a python RPC toolkit that among other protocols supports SOAP. It will create the WSDL for you, but if your objective is implementing the service described by the WSDL you already have then you'll have to fine tune your spyne service (written in python) until the generated WSDL matches the original

更新你可以使用spyne。它是一个 python RPC 工具包,在其他协议中支持 SOAP。它将为您创建 WSDL,但如果您的目标是实现您已经拥有的 WSDL 所描述的服务,那么您必须微调您的 spyne 服务(用 Python 编写),直到生成的 WSDL 与原始服务匹配