【问题标题】:xml with multiple data processing in django spyne在 django spyne 中具有多个数据处理的 xml
【发布时间】:2015-10-21 22:13:36
【问题描述】:

我有一个运行 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 验证器会导致错误。

问题是如何更改代码以接受多个标签。

P.S:如果有人告诉我如何解决我的命名空间问题,我将不胜感激。 :)

EDIT2:

这是我在使用 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>

【问题讨论】:

  • 是的,这是可能的。不过,您需要先显示一些代码。
  • @BurakArslan 我已经编辑了我的问题。提前谢谢你。
  • 首先,Spyne 不支持 body 元素下的多个标签。欢迎使用补丁。
  • 至于 lxml 验证失败,请同时发布您获得的服务器端回溯,以便我对此发表评论..
  • @BurakArslan 谢谢你,我不确定你是不是这个意思,但我已经添加了我的错误响应。

标签: xml django web-services spyne


【解决方案1】:

在定义您的ComplexModels 以供外部(非python)系统访问时,请使用此语法。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 2020-02-29
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    相关资源
    最近更新 更多