Question

I run a soap server in django.

Is it possible to create a soap method that returns a soaplib classmodel instance without <{method name}Response><{method name}Result> tags?

For example, here is a part of my soap server code:

# -*- coding: cp1254 -*-
from soaplib.core.service import rpc, DefinitionBase, soap
from soaplib.core.model.primitive import String, Integer, Boolean
from soaplib.core.model.clazz import Array, ClassModel 
from soaplib.core import Application
from soaplib.core.server.wsgi import Application as WSGIApplication
from soaplib.core.model.binary import Attachment    


class documentResponse(ClassModel):
    __namespace__ = ""
    msg = String
    hash = String


class MyService(DefinitionBase):
    __service_interface__ = "MyService"


    __port_types__ = ["MyServicePortType"]




    @soap(String, Attachment, String ,_returns=documentResponse,_faults=(MyServiceFaultMessage,)  , _port_type="MyServicePortType"  )
    def sendDocument(self, fileName, binaryData, hash ):

        binaryData.file_name = fileName
        binaryData.save_to_file()


        resp = documentResponse()
        resp.msg = "Saved"
        resp.hash = hash
        return resp

and it responses like that:

 <senv:Body>
   <tns:sendDocumentResponse>
     <tns:sendDocumentResult>
      <hash>14a95636ddcf022fa2593c69af1a02f6</hash>
      <msg>Saved</msg>
    </tns:sendDocumentResult>
  </tns:sendDocumentResponse>
</senv:Body>

But i need a response like this:

<senv:Body>
   <ns3:documentResponse>
     <hash>A694EFB083E81568A66B96FC90EEBACE</hash>
     <msg>Saved</msg>
  </ns3:documentResponse>
</senv:Body>

What kind of configurations should i make in order to get that second response i mentioned above ?

Thanks in advance.

Was it helpful?

Solution

I haven't used Python's SoapLib yet, but had the same problem while using .NET soap libs. Just for reference, in .NET this is done using the following decorator:

[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]

I've looked in the soaplib source, but it seems it doesn't have a similar decorator. The closest thing I've found is the _style property. As seen from the code https://github.com/soaplib/soaplib/blob/master/src/soaplib/core/service.py#L124 - when using

@soap(..., _style='document')

it doesn't append the %sResult tag, but I haven't tested this. Just try it and see if this works in the way you want it.

If it doesn't work, but you still want to get this kind of response, look at Spyne:

http://spyne.io/docs/2.10/reference/decorator.html

It is a fork from soaplib(I think) and has the _soap_body_style='bare' decorator, which I believe is what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top