Efrin
Efrin

Reputation: 2423

Python Spyne - SOAP Server - This element is not expected. Expected is ( {http:// } Element_name )

I am getting an error This element is not expected.

Expected is {http://com.blablabla.fbs.webservice.receiver/webservice}Sms_1 ).

I don't understand what is it and it's another day when I am trying to fix it.

Please provide me some tips or suggestions which could lead me to fixing the issue.

XML which is sent

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body>
<ns1:ReceiveSms xmlns:ns1='http://com.blablabla.fbs.webservice.receiver/webservice'>
<Sms_1><id>1231231231</id><from>124214124</from><operator>test</operator><to>482414245</to>
<text>Hallo</text><numberOfParts>1</numberOfParts></Sms_1></ns1:ReceiveSms></env:Body></env:Envelope> 

Error message

senv:Client.SchemaValidationError<string>:3:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'Sms_1': This element is not expected. Expected is ( {http://com.blablabla.fbs.webservice.receiver/webservice}Sms_1 ).

Code:

class sms(ComplexModel):
    _type_info = {
        "text": Unicode,
        'from': Unicode,
        "id": Long,
        "operator": Unicode,
        "to": Unicode,
        "numberOfParts": Integer,
    }


class ReceiverService(ServiceBase):

    @srpc(Array(sms), _returns=Unicode)
    def ReceiveSms(Sms_1):
        for data in Sms_1:
            test = data.get_deserialization_instance()
            print test.operator
        return Sms_1

application = Application([ReceiverService],
    tns='http://com.blablabla.fbs.webservice.receiver/webservice',
    name="ReceiverService",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11()
    )

hello_app = csrf_exempt(DjangoApplication(application))

Upvotes: 2

Views: 1781

Answers (1)

Burak Arslan
Burak Arslan

Reputation: 8011

Your request document is wrong. You're missing

  1. The namespace prefix in the Sms_1 tag.
  2. The namespace declaration in the object definition.

Here's the correct object declaration:

class sms(ComplexModel):
    __namespace__ = 'http://com.blablabla.fbs.webservice.receiver/webservice'
    _type_info = {
        "text": Unicode,
        'from': Unicode,
        "id": Long,
        "operator": Unicode,
        "to": Unicode,
        "numberOfParts": Integer,
    }

Here's a fixed request document:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <ns1:ReceiveSms xmlns:ns1="http://com.blablabla.fbs.webservice.receiver/webservice">
      <ns1:Sms_1>
        <ns1:id>1231231231</ns1:id>
        <ns1:from>124214124</ns1:from>
        <ns1:operator>test</ns1:operator>
        <ns1:to>482414245</ns1:to>
        <ns1:text>Hallo</ns1:text>
        <ns1:numberOfParts>1</ns1:numberOfParts>
      </ns1:Sms_1>
    </ns1:ReceiveSms>
  </env:Body>
</env:Envelope>

Upvotes: 3

Related Questions