SOAP web service with soaplib 0.9+
来源:互联网 发布:淘宝数据分析平台 编辑:程序博客网 时间:2024/06/03 23:42
from soaplib.serializers.primitive import Boolean, Stringfrom soaplib.service import DefinitionBase, rpcfrom soaplib.wsgi import Applicationfrom django.http import HttpResponse# the class with actual web methodsclass MySOAPService(DefinitionBase): @rpc(String, String, _returns=Boolean) def Test(self, f1, f2): return True# the class which acts as a wrapper between soaplib WSGI functionality and Djangoclass DjangoSoapApp(Application): def __call__(self, request): # wrap the soaplib response into a Django response object django_response = HttpResponse() def start_response(status, headers): status, reason = status.split(' ', 1) django_response.status_code = int(status) for header, value in headers: django_response[header] = value response = super(DjangoSoapApp, self).__call__(request.META, start_response) django_response.content = '\n'.join(response) return django_response# the view to use in urls.pymy_soap_service = DjangoSoapApp([MySOAPService], __name__