[Soap-Python] soaplib 1.0.0-beta6 - Integration with Django

Devin Venable venable.devin at gmail.com
Tue Oct 5 15:43:41 CEST 2010


Burak,

The cat's out of the bag and there are a number of people using the Django
integration recipe.  When I upgraded to soaplib 1.0 my Django integration
also quit working, and it was based on the same snippet that Nick mentioned.

Nick should check out http://djangosnippets.org/snippets/2210/, which is an
updated snippet that shows the correct (or at least workable) way to do it
using soaplib 0.9 or greater.  This worked for me.

Devin

On Tue, Oct 5, 2010 at 8:33 AM, Burak Arslan <burak.arslan at arskom.com.tr>wrote:

>  On 10/05/10 15:47, Nick Ruiz wrote:
>
> Hi everyone,
>
> There is documentation online on how to create web services with soaplib
> 0.8 within a Django web application, but the code needs to be rewritten to
> work with soaplib 1.0.0-beta6. I tried updating my code to get a
> slightly-modified hello world web service working under a Django
> installation, but I receive the following error:
>
> Error was: 'serverland.dashboard.api.views.worker_service' is not a
> callable.
>
> Here is my base class for creating web services (soap_handler):
>
> from soaplib.service import DefinitionBase
> from soaplib.service import rpc
> from soaplib.serializers import primitive as soap_types
>
> from django.http import HttpResponse
>
> class DjangoSoapApp(DefinitionBase):
>
>     def call_wrapper(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(DefinitionBase, self).call_wrapper(request.META,
> start_response)
>         django_response.content = "\n".join(response)
>
>         return django_response
>
> Here is my service (created in views.py of my Django app):
>
> from soap_handler import DjangoSoapApp, rpc, soap_types
> from soaplib.serializers.clazz import Array
>
> class WorkerService(DjangoSoapApp):
>
>     __tns__ = 'http://my.namespace.org/soap/'
>
>     @rpc(soap_types.String, soap_types.Integer,
> _returns=Array(soap_types.String))
>     def say_hello(self, name, times):
>         results = []
>         for i in range(0, times):
>             results.append('Hello, %s'%name)
>         return results
>
> worker_service = WorkerService()
>
> And here are my url pattern definitions:
>     url(r'^soap/', 'serverland.dashboard.api.views.worker_service'),
>     url(r'^soap/service.wsdl',
> 'serverland.dashboard.api.views.worker_service')
>
> How should I modify the DjangoSoapApp to enable my web service to be
> callable within Django?
>
>
> i have never worked with django before. consequently the error does not
> mean anything to me.
>
> however, this bit is quite weird:
>
>
>         response = super(DefinitionBase, self).call_wrapper(request.META,
> start_response)
>         django_response.content = "\n".join(response)
>
> the response is not a string, but a native python object. you should call
> the corresponding to_xml to deobjectify that, and call etree.tostring on
> that to serialize it to a string. look at what happens in wsgi.py after the
> call_wrapper is called.
>
> can't django just map wsgi application to a url regex? i'd do it that way.
>
> fwiw, i'm working on soaplib 2.0 which will be transport-agnostic. you
> could as well wait for that to stabilize.
>
> best,
> burak
>
>
>
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20101005/c2f349b0/attachment.html>


More information about the Soap mailing list