# soaplib_handler.py
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers import primitive as soap_types
from django.http import HttpResponse
class DjangoSoapApp(SimpleWSGISoapApp):
def __call__(self, request):
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(SimpleWSGISoapApp, self).__call__(request.META, start_response)
django_response.content = "\n".join(response)
return django_response
# views.py - sample view
from soaplib_handler import DjangoSoapApp, soapmethod, soap_types
class HelloWorldService(DjangoSoapApp):
__tns__ = 'http://my.namespace.org/soap/'
@soapmethod(soap_types.String, soap_types.Integer, _returns=soap_types.Array(soap_types.String))
def say_hello(self, name, times):
results = []
for i in range(0, times):
results.append('Hello, %s'%name)
return results
hello_world_service = HelloWorldService()
# urls.py
urlpatterns = patterns(
'',
(r'^hello_world/', 'foo.views.hello_world_service'),
(r'^hello_world/service.wsdl', 'foo.views.hello_world_service'),
)
can test it with a soaplib client:
from soaplib.client import make_service_client
from foo.views import HelloWorldService
client = make_service_client('http://localhost:8000/hello_world/', HelloWorldService())
client.say_hello('John', 2)
['Hello, John', 'Hello, John']