Python2.7下发布web service(二):服务发布示例
2013-12-18 00:00
253 查看
参考资料:(1) soaplib官方教程
(2) 官方示例,简单的hello world service
(3) 一份较好的中文文档示例
下载,cmd进目录,setup.py install
(2) 官方示例,简单的hello world service
(3) 一份较好的中文文档示例
服务声明
import soaplib from soaplib.core.service import rpc, DefinitionBase,soap #官方文档缺少import soap from soaplib.core.model.primitive import String, Integer from soaplib.core.server import wsgi from soaplib.core.model.clazz import Array class HelloWorldService(DefinitionBase): @soap(String,Integer,_returns=Array(String)) def say_hello(self,name,times): 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.core.Application([HelloWorldService], 'tns') wsgi_application = wsgi.Application(soap_application) server = make_server('localhost', 7789, wsgi_application) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5"
服务调用
from suds.client import Client hello_client = Client('http://localhost:7789/?wsdl') result = hello_client.service.say_hello("Dave", 5) print result #输出结果: #(stringArray){ # string[] = # "Hello, Dave", # "Hello, Dave", # "Hello, Dave", # "Hello, Dave", # "Hello, Dave", # }客户端调用服务,需要安装suds。
下载,cmd进目录,setup.py install
相关文章推荐
- python2.7下发布web service(一):环境搭建
- AXIS2发布WebService服务示例(Eclipse+AXIS)
- python实现探测socket和web服务示例
- .NET平台下Redis使用(六)【ServiceStack.Redis发布、订阅服务示例】
- 纯Python包发布setup脚本编写示例
- spring结合apache cxf发布web service服务
- CXF(2.7.10)利用Spring发布Web服务的简单示例
- Tuscany发布Web Service示例
- 通过Python脚本自动发布ArcGIS服务
- Python Web中REST API使用示例——基于云平台+云服务打造自己的在线翻译工具
- GlassFish发布Web Service服务和Eclipse 建立web Service测试客户端
- 纯Python包发布setup脚本编写示例
- python实现探测socket和web服务示例
- Python脚本实现自动发布地图服务
- 黑龙江大学 校园网 师生服务 身份验证 查成绩 查绩点等 API 以及示例程序 (Python 验证码自动识别)
- 9.Web Service Spring整合CXF之发布服务
- python实现监控windows服务并自动启动服务示例
- eoLinker-API_Shop_短信服务接口-调用示例代码,支持PHP、Python、Java等语言
- 通过Python脚本自动发布ArcGIS服务
- web service 初识 axis (二) 使用wsdd发布服务