dimanche 2 août 2015

xml with multiple data processing in django spyne

i have a server running django and spyne, i want to configure spyne to accept xml like below:

<soapenv:Envelope xmlns:soapenv="http://ift.tt/sVJIaE"
xmlns:loc="http://ift.tt/1noaANI">
<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>

is it possible? how should i do so?

and changing the client is impossible, so i have to work with this format.

EDIT:

what i have done till now:

model:

class ReceiptRequestItem(ComplexModel):
    __namespace__ = 'http://ift.tt/1noaANI'
    endpoint = Unicode()
    interfaceName = Unicode()
    correlator = Unicode()

service:

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

application:

mo_message_app = Application([MOMessageService],
                             'http://ift.tt/1noaANI',
                             in_protocol=Soap11(validator='soft'),
                             out_protocol=Soap11(), )

mo_message_service = csrf_exempt(DjangoApplication(mo_message_app))

this works when there is just one

<loc:sendSms>

though there is a problem with namespaces and lxml validator will result in error.

the question is how to change the code to accept multiple tags.

P.S: also i will be grateful if someone tell me how to fix my problem with namespaces. :)

EDIT2:

this is the error I encounter while using lxml validator:

<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope xmlns:senv="http://ift.tt/sVJIaE">
    <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://ift.tt/1gArPvF,
                {http://ift.tt/1OIdesO,
                {http://ift.tt/1gArRUy ).
            </faultstring>
            <faultactor></faultactor>
        </senv:Fault>
    </senv:Body>
</senv:Envelope>

Aucun commentaire:

Enregistrer un commentaire