0

I'm trying to use spyne to implement a SOAP service in Python. My client sends SOAP requests like this:

<ns1:loadServices xmlns:ns1="dummy">
  <serviceParams xmlns="dummy">
    <header>
        <user>foo</user>
        <password>secret</password>
    </header>
  </serviceParams>
</ns1:loadServices>

But I have difficulties putting that structure into a spyne model.

So far I came up with this code:

class Header(ComplexModel):
    __type_name__ = 'header'
    user = Unicode
    password = Unicode


class serviceParams(ComplexModel):
    __type_name__ = 'serviceParams'
    header = Header()


class DummyService(ServiceBase):
    @rpc(serviceParams, _returns=Unicode)
    def loadServices(ctx, serviceParams):
        return '42'

The problem is that spyne generates and XSD like this:

...
<xs:complexType name="loadServices">
  <xs:sequence>
    <xs:element name="serviceParams" type="tns:serviceParams" minOccurs="0" nillable="true"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="serviceParams"/>
...

which is not what I want because essentially it says that "serviceParams" is just an empty tag without children.

Is that a bug in spyne? Or am I missing something?

Community
  • 1
  • 1
Felix Schwarz
  • 2,938
  • 4
  • 28
  • 41

1 Answers1

1

It turned out that this line was the culprit:

header = Header()

that should be:

header = Header

Very nasty behavior and really easy to overlook.

Felix Schwarz
  • 2,938
  • 4
  • 28
  • 41
  • Well, I agree it's a bit easy to overlook, but I'd say that's Python rather than Spyne. Calling a class instantiates that class. Maybe Spyne could emit a warning or something when it sees an instance of a type marker as I can't think of a valid use case for using instances of markers where markers themselves should be used. – Burak Arslan Sep 10 '13 at 12:03
  • yes, I think it's "nasty" because spyne just silently ignores the element. If there was an exception or at least a clearly visible warning (e.g. using the warnings module) that would be a completely different story. – Felix Schwarz Sep 10 '13 at 14:21
  • Right. It's quite easy to implement actually. If you need it ASAP, patches are welcome :) See: https://github.com/arskom/spyne/issues/273 – Burak Arslan Sep 10 '13 at 15:32