pythonpython-3.xsoaprequestspyne

Using Spyne, trying to condense the multiple namespaces generated to a single namespace in a SOAP request


I have the below SOAP request generated by SOAPUI using ComplexModel approach of Spyne request.

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:ava="Namespace-1"
        xmlns:book="spyne.example.django.models">
       <soapenv:Header/>
       <soapenv:Body>
          <ava:GetChangesRequest>
             <book:RequestIds>String1</book:RequestIds>
             <book:From>2019-09-22</book:From>
             <!--Optional:-->
             <book:StartIndex>0</book:StartIndex>
          </ava:GetChangesRequest>
       </soapenv:Body>
    </soapenv:Envelope>

And ComplexModel of request is below.

class GetChangesRequest(ComplexModel):
    RequestIds = Unicode.customize(min_occurs=1)
    From = Date.customize(min_occurs=1)
    StartIndex = Integer.customize(default=0, min_occurs=0)

And @rpc definition is

 @rpc(
        GetChangesRequest,
        _returns=GetChangesResponse,
        _in_message_name='GetChangesRequest',
        _out_message_name='GetChangesResponse',
        _body_style='bare',
    )

Now I am looking to avoid these multiple namespaces in the Request.

Followed this Stackoverflow post Remove the namespace from Spyne response variables

and was able to manage customize the response the way I wanted. But could not find any such approach for the SOAP Request thru Spyne.

Any pointers here will help.


Solution

  • You need to have the tns argument you pass to the Application to be the same as the GetChangesRequest namespace value.

    ie

    class GetChangesRequest(ComplexModel):
        __namespace__ = 'Namespace-1'
    
        RequestIds = Unicode.customize(min_occurs=1)
        From = Date.customize(min_occurs=1)
        StartIndex = Integer.customize(default=0, min_occurs=0)