本文介绍了使用soaplib(服务器)和suds(客户端)的Pythonsoap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与:Python SOAP 服务器/客户端

soap 与 python 的情况,有推荐使用soaplib(http://wiki.github.com/jkp/soaplib)作为肥皂服务器和 suds(https://fedorahosted.org/suds/) 作为肥皂客户端.我的目标是在 python 中创建可以被多个客户端(java 等)使用的肥皂服务.我尝试了soaplib中的HelloWorld示例(http://trac.optio.webfactional.com/wiki/你好世界).当客户端也使用 soaplib 时,它运行良好.

然后,我尝试使用 suds 作为使用 HelloWorld 服务的客户端,但它失败了.- 为什么会这样?不同客户端使用soaplib 服务器是否存在问题?

这里是服务器的代码:

from soaplib.wsgi_soap import SimpleWSGISoapApp从soaplib.service 导入soapmethod从soaplib.serializers.primitive 导入字符串、整数、数组代码类 HelloWorldService(SimpleWSGISoapApp):@soapmethod(String,Integer,_returns=Array(String))def say_hello(self,name,times):结果 = []对于我在范围内(0,次):results.append('你好,%s'%name)返回结果如果 __name__=='__main__':从cherrypy.wsgiserver 导入CherryPyWSGIServer#fromcherrypy._cpwsgiserver 导入 CherryPyWSGIServer# 这个例子使用CherryPy2.2,CherryPy 3.0使用cherrypy.wsgiserver.CherryPyWSGIServerserver = CherryPyWSGIServer(('localhost',7789),HelloWorldService())服务器启动()

这是soaplib客户端:

from soaplib.client import make_service_client从 SoapServerTest_1 导入 HelloWorldServiceclient = make_service_client('http://localhost:7789/',HelloWorldService())打印 client.say_hello("Dave",5)

结果:

>>>['你好,戴夫','你好,戴夫','你好,戴夫','你好,戴夫','你好,戴夫']

这是 suds 客户端:

from suds.client import Clienturl = 'http://localhost:7789/HelloWordService?wsdl'客户 1 = 客户(网址)client1.service.say_hello("戴夫",5)

结果:

 >>>调试时未处理的异常...回溯(最近一次调用最后一次):文件C:Python25Libsite-packagesRTEPSequencingSoapClientTest_1.py",第 10 行,在 <module>client1.service.say_hello("戴夫",5)文件c:python25libsite-packagessudsclient.py",第 537 行,在 __call__ 中返回 client.invoke(args, kwargs)文件c:python25libsite-packagessudsclient.py",第 597 行,在调用中结果 = self.send(msg)文件c:python25libsite-packagessudsclient.py",第 626 行,发送结果 = self.succeeded(绑定,reply.message)文件c:python25libsite-packagessudsclient.py",第 658 行,成功r, p = binding.get_reply(self.method, reply)文件c:python25libsite-packagessudsindingsinding.py",第 158 行,在 get_reply 中结果 = unmarshaller.process(节点 [0],已解决)文件c:python25libsite-packagessudsumx	yped.py",第 66 行,正在处理中返回 Core.process(self, content)文件c:python25libsite-packagessudsumxcore.py",第 48 行,正在处理中返回 self.append(content)文件c:python25libsite-packagessudsumxcore.py",第 63 行,附加self.append_children(内容)文件c:python25libsite-packagessudsumxcore.py",第 140 行,在 append_children 中cval = self.append(cont)文件c:python25libsite-packagessudsumxcore.py",第 61 行,附加self.start(内容)文件c:python25libsite-packagessudsumx	yped.py",第 77 行,在开始found = self.resolver.find(content.node)文件c:python25libsite-packagessuds
esolver.py",第 341 行,在 find框架=框架(结果,解决=已知,祖先=祖先)文件c:python25libsite-packagessuds
esolver.py",第 473 行,在 __init__ 中已解决 = type.resolve()文件c:python25libsite-packagessudsxsdsxbasic.py",第 63 行,解析提高 TypeNotFound(qref)TypeNotFound: 类型未找到: '(string, HelloWorldService.HelloWorldService, )'
解决方案

尝试将原语导入您的类:

class HelloWorldService(SimpleWSGISoapApp):从soaplib.serializers.primitive 导入字符串、整数、数组代码@soapmethod(String,Integer,_returns=Array(String))

This question is related to:Python SOAP server / client

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.My target is to create soap services in python that can be consumed by several clients (java, etc).I tried the HelloWorld example from soaplib (http://trac.optio.webfactional.com/wiki/HelloWorld).It works well when the client is also using soaplib.

Then, I tried to use suds as client consuming the HelloWorld services and it fail.-Why this is happening? Does soaplib server has problems to consumed by different clients?

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:

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:

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:Python25Libsite-packagesRTEPSequencingSoapClientTest_1.py", line 10, in <module>
    client1.service.say_hello("Dave",5)
  File "c:python25libsite-packagessudsclient.py", line 537, in __call__
    return client.invoke(args, kwargs)
  File "c:python25libsite-packagessudsclient.py", line 597, in invoke
    result = self.send(msg)
  File "c:python25libsite-packagessudsclient.py", line 626, in send
    result = self.succeeded(binding, reply.message)
  File "c:python25libsite-packagessudsclient.py", line 658, in succeeded
    r, p = binding.get_reply(self.method, reply)
  File "c:python25libsite-packagessudsindingsinding.py", line 158, in get_reply
    result = unmarshaller.process(nodes[0], resolved)
  File "c:python25libsite-packagessudsumx	yped.py", line 66, in process
    return Core.process(self, content)
  File "c:python25libsite-packagessudsumxcore.py", line 48, in process
    return self.append(content)
  File "c:python25libsite-packagessudsumxcore.py", line 63, in append
    self.append_children(content)
  File "c:python25libsite-packagessudsumxcore.py", line 140, in append_children
    cval = self.append(cont)
  File "c:python25libsite-packagessudsumxcore.py", line 61, in append
    self.start(content)
  File "c:python25libsite-packagessudsumx	yped.py", line 77, in start
    found = self.resolver.find(content.node)
  File "c:python25libsite-packagessuds
esolver.py", line 341, in find
    frame = Frame(result, resolved=known, ancestry=ancestry)
  File "c:python25libsite-packagessuds
esolver.py", line 473, in __init__
    resolved = type.resolve()
  File "c:python25libsite-packagessudsxsdsxbasic.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))

这篇关于使用soaplib(服务器)和suds(客户端)的Pythonsoap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 03:27