Create multiple services using Spyne

蹲街弑〆低调 提交于 2019-12-11 08:39:12

问题


I'm trying to create a SOAP web services using Spyne. Based on the simple Hello example, I want to create 2 different services:

from spyne.application import Application
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication

from spyne.decorator import rpc
from spyne.service import ServiceBase
from spyne.model.complex import Iterable
from spyne.model.primitive import Unicode

class HelloWorldService(ServiceBase):
    @rpc(Unicode, _returns=Iterable(Unicode))
    def say_hello(ctx, name):
        return [u'Hello, %s' % name]

class HelloWorldService1(ServiceBase):
    @rpc(Unicode, _returns=Iterable(Unicode))
    def say_hello1(ctx, name):
        return [u'Hello, %s' % name]

if __name__=='__main__':
    from wsgiref.simple_server import make_server

    application = Application([HelloWorldService, HelloWorldService1],
                'spyne.examples.hello.soap',
                in_protocol=Soap11(validator='lxml'),
                out_protocol=Soap11()
            )
    wsgi_application = WsgiApplication(application)

    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

However, when I try to consume those services using suds:

from suds.client import Client
client = Client('http://localhost:8000/?wsdl')
print client

There is only one service available:

Service ( HelloWorldService ) tns="spyne.examples.hello.soap"
   Prefixes (1)
      ns0 = "spyne.examples.hello.soap"
   Ports (1):
      (Application)
         Methods (1):
            say_hello(xs:string name, xs:integer times, )
         Types (3):
            say_hello
            say_helloResponse
            stringArray

So, I wonder if there is anything that I missed. Moreover, if it is possible, can anyone tell me how to create multiple services, each of which has its own wsdl file, in Spyne.


回答1:


Your code is correct and would show both say_hello and say_hello1 methods. Maybe you should try again after clearing your client's wsdl cache.

You can look at the actual wsdl document by visiting http://localhost:8000/?wsdl in your browser.



来源:https://stackoverflow.com/questions/20217104/create-multiple-services-using-spyne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!