# -*- coding: utf-8 -*-
u"""
需要安装 插件-soaplib VERSION = '2.0.0'
"""
import os
import sys
import soaplib
from soaplib.core.service import soap
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.server.wsgi import Application as WSGIApplication
from soaplib.core import Application
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
import settings
import traceback
import datetime
from django.http import HttpResponse
from django.utils.log import getLogger
logger = getLogger( "default" )
class DjangoSoapApp(WSGIApplication):
"""
Generic Django view for creating SOAP web services (works with soaplib 2.0)
Based on http://djangosnippets.org/snippets/2210/
"""
csrf_exempt = True
def __init__(self, services, tns):
"""Create Django view for given SOAP soaplib services and tns"""
return super(DjangoSoapApp, self).__init__(Application(services, tns))
def __call__(self, request):
django_response = HttpResponse()
def start_response(status, headers):
django_response.status_code = int(status.split(' ', 1)[0])
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
u"""
需要安装 插件-soaplib VERSION = '2.0.0'
"""
import os
import sys
import soaplib
from soaplib.core.service import soap
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.server.wsgi import Application as WSGIApplication
from soaplib.core import Application
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
import settings
import traceback
import datetime
from django.http import HttpResponse
from django.utils.log import getLogger
logger = getLogger( "default" )
class DjangoSoapApp(WSGIApplication):
"""
Generic Django view for creating SOAP web services (works with soaplib 2.0)
Based on http://djangosnippets.org/snippets/2210/
"""
csrf_exempt = True
def __init__(self, services, tns):
"""Create Django view for given SOAP soaplib services and tns"""
return super(DjangoSoapApp, self).__init__(Application(services, tns))
def __call__(self, request):
django_response = HttpResponse()
def start_response(status, headers):
django_response.status_code = int(status.split(' ', 1)[0])
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
#这几个引用,soablib2.0的位置跟0.9+之类的版本不一样了
from soaplib.core.model.primitive import Boolean, String
from soaplib.core.service import DefinitionBase, rpc
# the class with actual web methods
class MySOAPService(DefinitionBase):
@rpc(String, String, _returns=Boolean)
def Test(self, f1, f2):
return True
@rpc(String, _returns=String)
def HelloWorld(self, name):
return 'Hello %s!' %name
my_soap_service = DjangoSoapApp([MySOAPService], 'laonan.net')
urls.py里的代码:
url(r'^my-soap-service/service', 'yourproject.yourapp.views.my_soap_service')
wsdl地址:http://127.0.0.1:8000/my-soap-service/service?wsdl
SOAPpy.SOAPProxy("http://127.0.0.1:8000/my-soap-service/service?wsdl
")