简体   繁体   English

Python soaplib和Django

[英]Python soaplib and Django

I'm trying to develop a SOAP Web Service in Django 1.5.2 with Python 2.7.3 and soaplib 0.8.1. 我正在尝试在Django 1.5.2中使用Python 2.7.3和soaplib 0.8.1开发SOAP Web服务。 Everything works fine at the moment, but now i need to add namespace to @soapmethod response. 目前一切正常,但是现在我需要在@soapmethod响应中添加名称空间。

This is my view: 这是我的看法:

from sms.soaplib_handler import DjangoSoapApp, soapmethod, soap_types
from django.views.decorators.csrf import csrf_exempt


class SmsGatewayService(DjangoSoapApp):

    __tns__ = 'http://mismsgw01.milano.ea.it/soap'

    @soapmethod(
        soap_types.String, 
        soap_types.String, 
        soap_types.String, 
        soap_types.Integer,
        soap_types.Boolean, 
        soap_types.Boolean, 
        soap_types.String, 
        _returns=soap_types.Any
    )
    def sendSms(
        self, 
        sendTo, 
        numSender,
        senderDescription,
        timeToLive,
        isDelivered,
        isStatistics,
        messageText
    ):

        retCode = '<retCode>OK</retCode>'

        return retCode

sms_gateway_service = csrf_exempt(SmsGatewayService())

and this is the response when i call the method: 这是我调用该方法时的响应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <sendSmsResponse>
         <sendSmsResult>
            <retCode>OK</retCode>
         </sendSmsResult>
      </sendSmsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Anyone can help me? 有人可以帮助我吗? How i can modify a soap response? 我如何修改肥皂反应? I need to have something similar to: 我需要类似以下内容:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <sendSmsResponse xmlns="http://mismsgw01.milano.ea.it/soap">
         <retCode>OK</retCode>
      </sendSmsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thanks in advance 提前致谢

You should use Spyne instead of SoapLib. 您应该使用Spyne而不是SoapLib。 As Spyne was built from soapLib, the spirit of the code will remain and Spyne works fine with its own wsdl. 由于Spyne是由soapLib构建的,因此代码的精神将保持不变,并且Spyne可以使用自己的wsdl正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM