2010-01-02 127 views
11

這個問題是有關: Python SOAP server/clientPython的肥皂使用soaplib(服務器)和泡沫(客戶端)

與蟒蛇肥皂的情況下,也有使用soaplib(http://wiki.github.com/jkp/soaplib)作爲SOAP服務器和泡沫(推薦作爲肥皂客戶端。 我的目標是在python中創建soap服務,可以被幾個客戶端(java等)使用。 我試過soaplib的HelloWorld例子(http://trac.optio.webfactional.com/wiki/HelloWorld)。 當客戶端也使用soaplib時,它工作得很好。

然後,我嘗試使用泡沫客戶端消費HelloWorld服務,它失敗。 - 爲什麼發生這種情況? soaplib服務器是否有問題要由不同的客戶端使用?

這裏爲服務器的代碼:

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() 

這是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) 

結果:

>>> ['Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave', 'Hello, Dave'] 

這是泡沫客戶端:

from suds.client import Client 
url = 'http://localhost:7789/HelloWordService?wsdl' 
client1 = Client(url) 
client1.service.say_hello("Dave",5) 

結果:

>>> 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,)' 
+1

我只是今天用現有資源嘗試,並得到與原始海報完全相同的問題。添加導入語句並沒有幫助(事實上,您可以查看原始代碼並查看導入的基元)。 – user343574 2010-06-04 01:27:01

回答

1

嘗試導入元到類:

class HelloWorldService(SimpleWSGISoapApp): 
    from soaplib.serializers.primitive import String, Integer, Arraycode 
    @soapmethod(String,Integer,_returns=Array(String))