django soap

# -*- 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


 

#这几个引用,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")


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值