soaplib helloworld.py

来源:互联网 发布:linux查看目录的权限 编辑:程序博客网 时间:2024/05/24 04:35
#!/usr/bin/env python# -*- coding: utf-8 -*-## soaplib - Copyright (C) 2009 Aaron Bickell, Jamie Kirkpatrick## This library is free software; you can redistribute it and/or# modify it under the terms of the GNU Lesser General Public# License as published by the Free Software Foundation; either# version 2.1 of the License, or (at your option) any later version.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public# License along with this library; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301#from soaplib.service import rpcfrom soaplib.service import DefinitionBasefrom soaplib.serializers.primitive import String, Integerfrom soaplib.wsgi import Applicationfrom soaplib.serializers.clazz import Array'''This is a simple HelloWorld example to show the basics of writinga webservice using soaplib, starting a server, and creating a serviceclient.'''class HelloWorldService(DefinitionBase):    @rpc(String, Integer, _returns=Array(String))    def say_hello(self, name, times):        '''Docstrings for service methods appear as documentation in the wsdl<b>what fun</b>@param name the name to say hello to@param the number of times to say hello@return the completed array'''        results = []        for i in range(0, times):            results.append('Hello, %s' % name)        return resultsif __name__=='__main__':    try:        from wsgiref.simple_server import make_server        server = make_server('localhost', 7789, Application([HelloWorldService], 'tns'))        server.serve_forever()    except ImportError:        print "Error: example server code requires Python >= 2.5"


原创粉丝点击