Web.py Cookbook 简体中文版 - 用soaplib实现webservice
2012-11-23 11:01
337 查看
问题
如何用soaplib实现webservice?解法
Optio的soaplib通过用装饰器指定类型,从而直接编写SOAP web service。而且它也是到目前为止,唯一为web service提供WSDL文档的Python类库。import web from soaplib.wsgi_soap import SimpleWSGISoapApp from soaplib.service import soapmethod from soaplib.serializers import primitive as soap_types urls = ("/hello", "HelloService", "/hello.wsdl", "HelloService", ) render = web.template.Template("$def with (var)\n$:var") class SoapService(SimpleWSGISoapApp): """Class for webservice """ #__tns__ = 'http://test.com' @soapmethod(soap_types.String,_returns=soap_types.String) def hello(self,message): """ Method for webservice""" return "Hello world "+message class HelloService(SoapService): """Class for web.py """ def start_response(self,status, headers): web.ctx.status = status for header, value in headers: web.header(header, value) def GET(self): response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response) return render("\n".join(response)) def POST(self): response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response) return render("\n".join(response)) app=web.application(urls, globals()) if __name__ == "__main__": app.run()
可以用soaplib客户端测试一下:
>>> from soaplib.client import make_service_client >>> from test import HelloService >>> client = make_service_client('http://localhost:8080/hello', HelloService()) >>> client.hello('John') 'Hello world John'
可以在http://localhost:8080/hello.wsdl查看WSDL。
欲了解更多,请查看 soaplib,
相关文章推荐
- Web.py Cookbook 简体中文版 - 在PostgreSQL下实现用户认证
- Web.py Cookbook 简体中文版 - 在webpy中使用Mako模板引擎
- Web.py Cookbook 简体中文版 - deploying web.py with nginx and mod_wsgi
- Web.py Cookbook 简体中文版 - db.delete 数据删除
- Web.py Cookbook 简体中文版
- Web.py Cookbook 简体中文版 - Use Jinja2 template engine in webpy
- Web.py Cookbook 简体中文版 - 使用Apache + mod_wsgi部署webpy应用
- Web.py Cookbook 简体中文版 - 自定义NotFound消息
- Web.py Cookbook 简体中文版 - Import functions into templates
- Web.py Cookbook 简体中文版 - 管理自带webserver日志
- Web.py Cookbook 简体中文版 - web.ctx
- Web.py Cookbook 简体中文版 - 在webpy中使用Cheetah模板引擎
- Web.py Cookbook 简体中文版 - 上传文件大小限定
- Web.py Cookbook 简体中文版 - 如何操作Cookie
- Web.py Cookbook 简体中文版 - 使用子应用
- Web.py Cookbook 简体中文版 - CGI deployment on Apache
- Web.py Cookbook 简体中文版 - 如何流传输大文件
- Web.py Cookbook 简体中文版 - 站点布局模板
- Web.py Cookbook 简体中文版 - 如何使用web.background
- Web.py Cookbook 简体中文版 - 保存上传的文件