简体   繁体   中英

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. Everything works fine at the moment, but now i need to add namespace to @soapmethod response.

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. As Spyne was built from soapLib, the spirit of the code will remain and Spyne works fine with its own wsdl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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