【问题标题】:python django soaplib response with classmodel issuepython django soaplib响应与classmodel问题
【发布时间】:2013-12-08 11:10:39
【问题描述】:

我在 django 中运行一个肥皂服务器。

是否可以创建一个返回soaplib 类模型实例而没有 标签的soap 方法?

例如,这是我的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>

我应该进行什么样的配置才能获得我上面提到的第二个响应?

提前致谢。

【问题讨论】:

  • u.unver34 你能分享什么对你有用吗?
  • 当然了,上面的方法我都没用过,我找到了不同的方法。根据一些关键字,我在 django soap 服务器的返回点用我需要的树形式替换了不需要的标签和所有响应方案树。

标签: python soap xml-namespaces tns soaplib


【解决方案1】:

我还没有使用过 Python 的 SoapLib,但是在使用 .NET 肥皂库时遇到了同样的问题。仅供参考,在 .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' 装饰器,我相信这就是你想要的。

【讨论】:

    猜你喜欢
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多