使用Spyne创建多个服务 [英] Create multiple services using Spyne

查看:301
本文介绍了使用Spyne创建多个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spyne创建SOAP Web服务.基于简单的您好示例,我要创建2种不同的服务:

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

只有一项服务可用:

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

所以,我想知道是否有什么我想念的.而且,如果可能的话,谁能告诉我如何在Spyne中创建多个服务,每个服务都有自己的wsdl文件.

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.

推荐答案

您的代码是正确的,并且将显示say_hello和say_hello1方法.也许您应该在清除客户端的wsdl缓存后再试一次.

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.

您可以通过在浏览器中访问http://localhost:8000/?wsdl来查看实际的wsdl文档.

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

这篇关于使用Spyne创建多个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆