2013-12-08 69 views
1

我在django運行一個soap服務器。python django soaplib回答classmodel問題

是否有可能創建一個soap方法,該方法返回一個soaplib classmodel實例,但不包含< {方法名稱}響應> < {方法名稱} Result>標記?

例如,這裏是我的SOAP服務器的代碼部分:

# -*- 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 

,並響應這樣的:

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

但我需要一個像這樣的迴應:

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

爲了得到我上面提到的第二個響應,我應該做什麼樣的配置?

在此先感謝。

+0

u.unver34你能分享一下你的工作嗎? – Priyeshj

+1

當然,我沒有使用上述方法,我找到了不同的方法。根據一些關鍵字,我用django soap服務器的返回點替換了那些不需要的標籤和所有響應方案樹。 –

回答

1

我還沒有使用過Python的SoapLib,但是在使用.NET soap庫的時候遇到了同樣的問題。僅供參考,在.NET這是使用做了以下裝飾:

[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)] 

我看了在soaplib源,但似乎沒有一個類似的裝飾。我發現的最接近的是_style屬性。根據碼https://github.com/soaplib/soaplib/blob/master/src/soaplib/core/service.py#L124看到 - 使用

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

當它不追加%sResult標籤,但我沒有測試過這一點。試試吧,看看它是否以你想要的方式工作。

如果它不工作,但你仍然希望得到這樣的回答,看看Spyne:

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

距離soaplib(我認爲)叉子和有_soap_body_style='bare'裝飾,我相信這是你想要的。