我有一个运行django和spyne的服务器,
我想将spyne配置为接受如下xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/sms/send/v4_0/local">
<soapenv:Header/>
<soapenv:Body>
<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
<endpoint></endpoint>
<interfaceName></interfaceName>
<correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>
<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
<endpoint></endpoint>
<interfaceName></interfaceName>
<correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>
.
.
.
</soapenv:Body>
</soapenv:Envelope>
有可能吗?
我该怎么做?
改变客户机是不可能的,所以我必须使用这种格式。
编辑:
我到现在为止所做的:
模型:
class ReceiptRequestItem(ComplexModel):
__namespace__ = 'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local'
endpoint = Unicode()
interfaceName = Unicode()
correlator = Unicode()
服务:
class MOMessageService(ServiceBase):
@rpc(Unicode, Unicode, Unicode, ReceiptRequestItem,
_returns=Unicode,
_in_variable_names={'sender_name': 'senderName',
'receipt_request': 'receiptRequest'},
_operation_name='sendSms')
def send_sms(ctx, addresses, sender_name, message, receipt_request):
print addresses, sender_name, message, receipt_request
return
应用:
mo_message_app = Application([MOMessageService],
'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local',
in_protocol=Soap11(validator='soft'),
out_protocol=Soap11(), )
mo_message_service = csrf_exempt(DjangoApplication(mo_message_app))
如果只有一个
<loc:sendSms>
尽管名称空间和lxml验证器有问题,但会导致错误。
问题是如何更改代码以接受多个标记。
另外,如果有人告诉我如何解决我的名称空间问题,我将不胜感激。:)
编辑2:
这是我在使用lxml验证器时遇到的错误:
<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Body>
<senv:Fault>
<faultcode>senv:Client.SchemaValidationError</faultcode>
<faultstring>:1:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'endpoint': This element is not expected.
Expected is one of ( {http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}endpoint,
{http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}interfaceName,
{http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}correlator ).
</faultstring>
<faultactor></faultactor>
</senv:Fault>
</senv:Body>
</senv:Envelope>
最佳答案
在定义要由外部(非python)系统访问的ComplexModel
s时,请使用此语法。
class ReceiptRequestItem(ComplexModel):
__namespace__ = 'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local'
_type_info = [
('endpoint', Unicode)
('interfaceName', Unicode)
('correlator', Unicode)
]
见:
https://github.com/arskom/spyne/pull/313
https://github.com/arskom/spyne/pull/343