加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用soaplib 创建 WebService

发布时间:2020-12-16 21:47:26 所属栏目:安全 来源:网络整理
导读:经过多次实验失败的总结,发现官方给的soaplib或是yum,pip,easy_install 安装的都会存在问题(Python2.7)。所以把这个记下来以防不时之需。一定要从这里下载,才能保证源码可运行。 soaplib 组件下载 import soaplibfrom soaplib.service import rpcfrom so

经过多次实验失败的总结,发现官方给的soaplib或是yum,pip,easy_install 安装的都会存在问题(Python2.7)。所以把这个记下来以防不时之需。一定要从这里下载,才能保证源码可运行。

soaplib 组件下载

import soaplib

from soaplib.service import rpc
from soaplib.service import DefinitionBase
from soaplib.model.primitive import String,Integer

from soaplib.server import wsgi
from soaplib.model.clazz import Array

'''
This is a simple HelloWorld example to show the basics of writing
a webservice using soaplib,starting a server,and creating a service
client.
'''

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 results

if __name__=='__main__':
    try:
        from wsgiref.simple_server import make_server
        soap_application = soaplib.Application([HelloWorldService],'tns')
        wsgi_application = wsgi.Application(soap_application)

        print "listening to http://0.0.0.0:80"
        print "wsdl is at: http://127.0.0.1:80/?wsdl"

        server = make_server('223.223.83.238',80,wsgi_application)
        server.serve_forever()

    except ImportError:
        print "Error: example server code requires Python >= 2.5"
~                                                                                            

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读