Domanda

I am relatively new to SOAP frameworks and have been reading through Spynes docs and trying to figure out to build a service that accepts the following request:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://..." xmlns:xsi=http:/..." xmlns:xsd="http://...">
<SOAP-ENV:Body>
    <modifyRequest returnData="everything" xmlns="urn:...">
      <attr ID="..."/>
      <data>
      </data>
    </modifyRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have read through the docs but just have not seen enough more complex examples to figure out how to put together something to handle this. The <attr ID="..."/> tag must be processed for the ID attribute and the <data> tags contain some varying collection of additional xml. I understand its better to formally define the service but for now I was hoping to use anyXML (?) to accept whatever is in the tags. I need to accept and process the ID attribute along with its xml payload contained within the data tags.

I'd be grateful for any guidance, Thanks.

È stato utile?

Soluzione

Here's how you'd do it:

NS = 'urn:...'

class Attr(ComplexModel):
    __namespace__ = NS
    _type_info = [
        ('ID', XmlAttribute(UnsignedInteger32)),
    ]

class ModifyRequest(ComplexModel):
    __namespace__ = NS
    _type_info = [
        ('returnData', XmlAttribute(Unicode(values=['everything', 'something', 'anything', 'etc']))),
        ('attr', Attr),
        ('data', AnyXml),
    ]


class SomeService(ServiceBase):
    @rpc(ModifyRequest, _body_style='bare')
    def modifyRequest(ctx, request):
        pass

This requires Spyne 2.11 though, _body_style='bare' in problematic in 2.10 and older.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top