Login

Automatically expose soaplib methods in WSDL

Author:
AndrewIngram
Posted:
February 6, 2009
Language:
Python
Version:
1.0
Score:
1 (after 1 ratings)

This snippet is a replacement views.py for SOAP views with on-demand WSDL generation

It iterates over your installed apps looking for web_service.py in each one, any methods decorated with @soapmethod within web_service.py will automatically be imported into the local namespace making them visible in the WSDL.

It will blindly override local objects of the same name so it's not very safe (could do with some more error checks) but it works very well.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from soaplib_handler import DjangoSoapApp
from django.conf import settings
import inspect

class Service(DjangoSoapApp):
    for app in settings.INSTALLED_APPS:
        try:
            module = __import__(app + '.web_service', [], [], [''])
            for key in module.__dict__:
                func = module.__dict__[key]
                if inspect.isfunction(func):
                    if '_is_soap_method' in dir(func):
                        locals()[key] = func
        except ImportError, e:
            pass
service = Service()

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

miketeo (on March 11, 2009):

Hi, you have written just what i need for my django app.

Can you recommend where should the above code snippet be placed? How can i access the wsdl URL using the above code?

Thanks for your code. -- Michael

#

Please login first before commenting.