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__)
Comments
for test with suds:
python -c "import suds; print suds.client.Client('http://127.0.0.1:8000/guias/service.wsdl', cache=None).service.Test('1','2')"
#
Thanks a lot for this! I got it working only after using emilianoheyns' patch from Snippet #979 (I use raw_post_body instead of reconstructing the body by hand from request.POST):
#
nice snippet, but I catch 403 "CSRF token missing or incorrect." any ideas to solve it?
#
Try this to get around csrf protection:
#