[英]Python soap using soaplib (server) and suds (client)
This question is related to: Python SOAP server / client 这个问题与: Python SOAP服务器/客户端有关
In the case of soap with python, there are recommendation to use soaplib ( http://wiki.github.com/jkp/soaplib ) as soap server and suds ( https://fedorahosted.org/suds/ ) as soap client. 在使用python的soap的情况下,建议使用soaplib( http://wiki.github.com/jkp/soaplib )作为soap服务器和suds( https://fedorahosted.org/suds/ )作为soap客户端。 My target is to create soap services in python that can be consumed by several clients (java, etc). 我的目标是在python中创建可由多个客户端(java等)使用的soap服务。 I tried the HelloWorld example from soaplib ( http://trac.optio.webfactional.com/wiki/HelloWorld ). 我尝试了soaplib的HelloWorld示例( http://trac.optio.webfactional.com/wiki/HelloWorld )。 It works well when the client is also using soaplib. 当客户端也使用soaplib时,它运行良好。
Then, I tried to use suds as client consuming the HelloWorld services and it fail. 然后,我尝试使用suds作为消费HelloWorld服务的客户端,它失败了。 -Why this is happening? - 为什么会这样? Does soaplib server has problems to consumed by different clients? soaplib服务器是否有不同客户端使用的问题?
Here the code for the server: 这里是服务器的代码:
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Arraycode
class HelloWorldService(SimpleWSGISoapApp):
@soapmethod(String,Integer,_returns=Array(String))
def say_hello(self,name,times):
results = []
for i in range(0,times):
results.append('Hello, %s'%name)
return results
if __name__=='__main__':
from cherrypy.wsgiserver import CherryPyWSGIServer
#from cherrypy._cpwsgiserver import CherryPyWSGIServer
# this example uses CherryPy2.2, use cherrypy.wsgiserver.CherryPyWSGIServer for CherryPy 3.0
server = CherryPyWSGIServer(('localhost',7789),HelloWorldService())
server.start()
This is the soaplib client: 这是soaplib客户端:
from soaplib.client import make_service_client
from SoapServerTest_1 import HelloWorldService
client = make_service_client('http://localhost:7789/',HelloWorldService())
print client.say_hello("Dave",5)
Results: 结果:
>>> ['Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave']
This is the suds client: 这是suds客户端:
from suds.client import Client
url = 'http://localhost:7789/HelloWordService?wsdl'
client1 = Client(url)
client1.service.say_hello("Dave",5)
Results: 结果:
>>> Unhandled exception while debugging...
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\RTEP\Sequencing\SoapClientTest_1.py", line 10, in <module>
client1.service.say_hello("Dave",5)
File "c:\python25\lib\site-packages\suds\client.py", line 537, in __call__
return client.invoke(args, kwargs)
File "c:\python25\lib\site-packages\suds\client.py", line 597, in invoke
result = self.send(msg)
File "c:\python25\lib\site-packages\suds\client.py", line 626, in send
result = self.succeeded(binding, reply.message)
File "c:\python25\lib\site-packages\suds\client.py", line 658, in succeeded
r, p = binding.get_reply(self.method, reply)
File "c:\python25\lib\site-packages\suds\bindings\binding.py", line 158, in get_reply
result = unmarshaller.process(nodes[0], resolved)
File "c:\python25\lib\site-packages\suds\umx\typed.py", line 66, in process
return Core.process(self, content)
File "c:\python25\lib\site-packages\suds\umx\core.py", line 48, in process
return self.append(content)
File "c:\python25\lib\site-packages\suds\umx\core.py", line 63, in append
self.append_children(content)
File "c:\python25\lib\site-packages\suds\umx\core.py", line 140, in append_children
cval = self.append(cont)
File "c:\python25\lib\site-packages\suds\umx\core.py", line 61, in append
self.start(content)
File "c:\python25\lib\site-packages\suds\umx\typed.py", line 77, in start
found = self.resolver.find(content.node)
File "c:\python25\lib\site-packages\suds\resolver.py", line 341, in find
frame = Frame(result, resolved=known, ancestry=ancestry)
File "c:\python25\lib\site-packages\suds\resolver.py", line 473, in __init__
resolved = type.resolve()
File "c:\python25\lib\site-packages\suds\xsd\sxbasic.py", line 63, in resolve
raise TypeNotFound(qref)
TypeNotFound: Type not found: '(string, HelloWorldService.HelloWorldService, )'
try to import primitives into your class: 尝试将基元导入您的类:
class HelloWorldService(SimpleWSGISoapApp):
from soaplib.serializers.primitive import String, Integer, Arraycode
@soapmethod(String,Integer,_returns=Array(String))
如果您从主干获取最新的源代码,则会修复此错误,有关详细信息,请参阅https://github.com/soaplib/soaplib/pull/12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.