-
-
Save plq/1242760 to your computer and use it in GitHub Desktop.
# This is not yet included in main rpclib distribution because | |
# it does a lot of unnecessary copying. However, it's reportedly | |
# working fine, so if you're not caring that much about performance | |
# you can use this. | |
from rpclib.server.wsgi import WsgiApplication | |
from cStringIO import StringIO | |
from django.http import HttpResponse | |
class DjangoApplication(WsgiApplication): | |
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 | |
environ = request.META.copy() | |
body = ''.join(['%s=%s' % v for v in request.POST.items()]) | |
environ['CONTENT_LENGTH'] = len(body) | |
environ['wsgi.input'] = StringIO(body) | |
environ['wsgi.multithread'] = False | |
response = WsgiApplication.__call__(self, environ, start_response) | |
django_response.content = "\n".join(response) | |
return django_response |
from rpclib.server.django import DjangoApplication # not real import path. | |
from rpclib.model.primitive import String, Integer | |
from rpclib.model.complex import Iterable | |
from rpclib.service import ServiceBase | |
from rpclib.interface.wsdl import Wsdl11 | |
from rpclib.protocol.soap import Soap11 | |
from rpclib.application import Application | |
from rpclib.decorator import rpc | |
class HelloWorldService(ServiceBase): | |
@rpc(String, Integer, _returns=Iterable(String)) | |
def say_hello(ctx, name, times): | |
for i in xrange(times): | |
yield 'Hello, %s' % name | |
hello_world_service = DjangoApplication(Application([HelloWorldService], | |
'some.tns', | |
interface=Wsdl11(), | |
in_protocol=Soap11(), | |
out_protocol=Soap11() | |
)) |
for deploying to mod_wsgi, just use WsgiApplication.
I use as documented in Django 1.4 in my app.wsgi:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
which does:
from django.core.handlers.wsgi import WSGIHandler
def get_wsgi_application():
"""
The public interface to Django's WSGI support. Should return a WSGI
callable.
Allows us to avoid making django.core.handlers.WSGIHandler public API, in
case the internal WSGI implementation changes or moves in the future.
"""
return WSGIHandler()
but this isn't working with mod_wsgi :(
again, if you want to deploy to mod_wsgi, just avoid django and do
app=WsgiApplication(Application([HelloWorldService],
'some.tns',
interface=Wsdl11(),
in_protocol=Soap11(),
out_protocol=Soap11()
))
if this doesn't answer your question, ask it at soap@python.org, where other ml members can help you.
also, this is part of the rpclib already. there's an example project here:
https://github.com/arskom/rpclib/tree/a3b14df62da696960eb3157b65f5032f295cddf3/examples/django
How does your app.wsgi file looks like to deploy on Apache Webserver? Currently my Apache blocks upon first request as soon as I implement this Gist.