十年 » Blog Archive » SOAPPy编写SOAP服务
来源:百度文库 编辑:神马文学网 时间:2024/05/02 20:03:11
SOAPPy编写SOAP服务
以前使用过Java和Perl编写SOAP服务,还比较简单的,对应的库有Axis和SoapLite。最近由于一个项目大部分使用Python作为开发语言,考虑使用Python来编写SOAP对外提供服务。众所周知,Python的动态和简单是出了名的,用它编写SOAP服务也相当简单的,要比Java和Perl来得更轻松。
使用Python编写SOAP,可以下载SOAPPy库。
编写SOAP服务,用于获得服务器当前的时间:
importsyssys.path.insert (1, ‘..‘)from SOAPpy import *importtimedef ():return time.strftime(‘%Y-%m-%D %H:%M:%S‘, time.localtime()) = ‘http://tenyears.cn/‘ = SOAPServer (("localhost", 9000))server.registerKWFunction (gettime, namespace)try:while True:server.handle_request()except KeyboardInterrupt:pass
以下是访问该SOAP服务的客户端测试代码:
importsyssys.path.insert (1, ‘..‘)from SOAPpy import * = "http://localhost:9000/" = "http://tenyears.cn/" = SOAPProxy(endpoint, namespace=ns)print serv.gettime()
与其他语言相比,这已经简化了许多,而且可以在不用编写本地代码的情况下就直接调用SOAP服务的方法,这和访问本地服务一样,非常的轻松。现在唯一担心的是它的性能,因为简单一定会带来其他的问题。但对于目前而言,可以暂时不用考虑这个。
以前使用过Java和Perl编写SOAP服务,还比较简单的,对应的库有Axis和SoapLite。最近由于一个项目大部分使用Python作为开发语言,考虑使用Python来编写SOAP对外提供服务。众所周知,Python的动态和简单是出了名的,用它编写SOAP服务也相当简单的,要比Java和Perl来得更轻松。
使用Python编写SOAP,可以下载SOAPPy库。
编写SOAP服务,用于获得服务器当前的时间:
importsyssys.path.insert (1, ‘..‘)from SOAPpy import *importtimedef ():return time.strftime(‘%Y-%m-%D %H:%M:%S‘, time.localtime()) = ‘http://tenyears.cn/‘ = SOAPServer (("localhost", 9000))server.registerKWFunction (gettime, namespace)try:while True:server.handle_request()except KeyboardInterrupt:pass
以下是访问该SOAP服务的客户端测试代码:
importsyssys.path.insert (1, ‘..‘)from SOAPpy import * = "http://localhost:9000/" = "http://tenyears.cn/" = SOAPProxy(endpoint, namespace=ns)print serv.gettime()
与其他语言相比,这已经简化了许多,而且可以在不用编写本地代码的情况下就直接调用SOAP服务的方法,这和访问本地服务一样,非常的轻松。现在唯一担心的是它的性能,因为简单一定会带来其他的问题。但对于目前而言,可以暂时不用考虑这个。
十年 » Blog Archive » SOAPPy编写SOAP服务
十年 » Blog Archive » 远程运行Windows的程序
不许联想 » Blog Archive » 吃黑食
不许联想 » Blog Archive » 快乐与幽默
刻录事 Blog Archive verisign的个人身份服务
Linux内核之旅 ? Blog Archive ? 内核模块编程之进阶(四)-编写带参数...
Yee‘s Blog » Blog Archive » 我在Yo2Blog上启用的插件
Sociz 日志 » Blog Archive » Firefox 下的 Google Earth 插件
《槽边往事》---比特海日志 » Blog Archive » 好友集中营:Friendfeed
科学松鼠会 » Blog Archive » 看这片雪花:美丽外表下的大怪物?
面面的博客 » Blog Archive » 帮帮我,我不懂JavaScript!
天天向上 Blog Archive
Web 服务:Web 服务内幕:关于 Soap 的决策
Web 服务:Web 服务内幕:关于 Soap 的决策
中文键盘 --- 滯銷書 ? Blog Archive ?
了解 Web 服务规范,第 1 部分: SOAP
了解 Web 服务规范,第 1 部分: SOAP
用ATL编写Windows服务
碎片 Blog Archive Subversion(SVN)安装使用指南
Nirvana Studio Blog Archive 什么是 Cake? :: 分享...
會計人 Blog Archive 準備CIA考試經驗談
望月的博客 Blog Archive 搬家通知
Meng Yan ( 孟岩 ) @ Weblog ? Blog Archive ? Map...
白板报 ? Blog Archive ? 石家庄往事