SOAP web service with soaplib 0.9+

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from soaplib.serializers.primitive import Boolean, String
from soaplib.service import DefinitionBase, rpc
from soaplib.wsgi import Application

from django.http import HttpResponse

# the class with actual web methods
class 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 Django
class 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.py
my_soap_service = DjangoSoapApp([MySOAPService], __name__)

More like this

  1. django soaplib test client by erny 5 years ago
  2. soaplib service integration 2 by erny 5 years ago
  3. SOAP web service with soaplib 2.0 by treyh 2 years, 3 months ago
  4. Convert django model into soaplib model, to expose webservices by s.federici 5 years, 3 months ago
  5. SOAP views with on-demand WSDL generation by chewie 5 years, 8 months ago

Comments

andrewk (on March 2, 2011):

nice snippet, but I catch 403 "CSRF token missing or incorrect." any ideas to solve it?

#

ungenio41 (on October 12, 2011):

Try this to get around csrf protection:

from django.http import HttpResponse
from soaplib.wsgi import Application


class DjangoSoapApp(Application):
    csrf_exempt = True

    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)
        django_response.csrf_exempt = True
        return django_response

#

(Forgotten your password?)