打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用python发布基于soap的webservice(二)

用python发布基于soap的webservice(二)

在 用python发布基于soap的webservice(一) 文章中,咱用的是python自带的wsgiref包,它是一个轻量级的web服务器,用来做做测试啊,


调bug的之类的是可以的,但是直接拿来做真正的服务器却还是不行。 所以本文主要讨论的是如何用 python + nginx + fastcgi + flup  + soaplib

 这些工具来构建一个可以承受高并发的Webservice

=============================================================================================================

废话不多说,直接上代码 ,server.py
#!/usr/bin/python
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Array
from soaplib.wsgi_soap import SimpleWSGISoapApp

    
class HelloWorldService(SimpleWSGISoapApp):
    @soapmethod(String, _returns=String)
    def says(self,name):     
        return name
                     
def make_client():
    from soaplib.client import make_service_client
    client = make_service_client('http://192.168.1.87:17889', HelloWorldService())    (注1)
    return client

if __name__=='__main__':
    try:
       import flup.server.fcgi as flups
       #这里的HelloWorldService后面必须带括号,不然会出错
       #flups.WSGIServer(HelloWorldService(), multithreaded=True, multiprocess=False, bindAddress=('127.0.0.1', 17900)).run()  (注2)
       flups.WSGIServer(HelloWorldService()).run() (注3) 
    except ImportError:
       print "Error: example server code requires Python >= 2.5"    

 注1: 这里的17889是nginx对外公布的端口,注意和下边的 17900端口的区别

如果不想用fastcgi的形式运行的话,那么就用注2 的那行代码,并且直接在命令行里面输入:python  server.py(这里的17900监听的nginx,它只接受nginx传过来的参数,外部无法直接访问)

而如果要用fastcgi的话,那么就用注3的那行代码,并且在命令行输入  :
         spawn-fcgi -f /data/www/server.py -a 127.0.0.1 -p 17900 -u www -F 2   (spawn-fcgi的用法参照 nginx上用fastcgi配置python环境(二))
 
到这一步以后 ,我们就可以运行客户端代码 client.py
#!/usr/bin/python
  
from server import make_client  
a = make_client()  
print a.says('hello,world')  

直接python client.py,就可以得到 hello,world 的字样
来自:http://blog.163.com/sky20081816@126/blog/static/16476102320109156135531/
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
在Delphi中动态调用webservice
python REST讨论(收藏)
Python编写WebService SOAP之原型
RobotFrameWork WebService Soap接口测试 (一)
Qt实现访问WebService
十年 » Blog Archive » SOAPPy编写SOAP服务
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服