我正在尝试使用Python 2.7.3和soaplib 0.8.1在Django 1.5.2中开发SOAP Web服务。 目前一切正常,但现在我需要为@soapmethod响应添加名称空间。
这是我的观点:
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())
这是我调用方法时的响应:
<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>
任何人都可以帮助我吗?我如何修改肥皂反应?我需要有类似的东西:
<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>
提前致谢
答案 0 :(得分:0)
您应该使用Spyne而不是SoapLib。由于Spyne是使用soapLib构建的,所以代码的精神将保留下来,Spyne可以使用自己的wsdl工作正常。