【问题标题】:Modify WSDL in soap webservice with spyne of Python使用 Python 的 spyne 修改soap webservice 中的 WSDL
【发布时间】:2015-09-01 05:46:08
【问题描述】:

我正在使用 Django 和 Python 进行开发,我需要使用带有 2 个操作的 SOAP 发布 1 个服务。对于这个任务,我选择了 spyne 库:

http://spyne.io/#auxproc=Sync&s=aux

因为显然很容易理解并开始开发。我做了第一个例子并且很好,即使我用我的内部逻辑开发了我自己的方法。现在我需要开发其他最特别的功能。我当前的代码是:

class SopoSoap(ComplexModel):
    __namespace__ = 'http://service/service.wsdl'
    _type_info = {
        "field1": Integer(min_occurs = 1),
        "field2": Integer(min_occurs = 1),
        "field3": Unicode(min_occurs = 1),
        "field4": Unicode(min_occurs = 1),
        "field5": Unicode(min_occurs = 0),
    }

class NewIncidenceService(ServiceBase):
    @rpc(SopoSoap, _returns=Integer)
    def NewIncidence(sop):
        # my differetns operations in code
        return a.pk # integer value

application = Application([NewIncidenceService],
    tns=http://service/service.wsdl',
    in_protocol=Soap11(validator='lxml'),
    out_protocol=Soap11(cleanup_namespaces=True)
)

createSop_app = csrf_exempt(DjangoApplication(application))

有了这段代码,一切都很好,我生成的 wsdl 就是这个:

<wsdl:definitions xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="http://localhost/DEMAT/DEMAT_IncidenceManagement/service.wsdl" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:soap12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding/" targetNamespace="http://localhost/DEMAT/DEMAT_IncidenceManagement/service.wsdl" name="Application">...</wsdl:definitions>

现在我需要这些更改:

首先,如果我尝试这个来源:

class ResponseData(ComplexModel):
    message = Unicode
    codResultado = Integer


class CreateIncidenceService(ServiceBase):
    @rpc(SopoSoap, _returns=ResponseData)
    def NewIncidence(sop):
        try:
            # operations
            return ResponseData

我从来没有收到我的服务器的回答(Apache with django - wsgi.py),我需要更改 rpc 装饰器吗?返回的类型,我在哪里可以找到一个很好的傻瓜文档示例?

第二。这个对我来说很重要,我需要更改wsdl中特定元素的名称,例如:

<xs:complexType name="NewIncidenceResponse">
or this others:
<wsdl:message name="NewIncidence">
<wsdl:part name="NewIncidence" element="tns:NewIncidence"/>
</wsdl:message>
<wsdl:message name="NewIncidenceResponse">
<wsdl:part name="NewIncidenceResponse" element="tns:NewIncidenceResponse"/>
</wsdl:message>

名字,只有名字,我想应该这么简单吧,因为在Java或.net中你可以毫无问题地改变这些参数的名字,但是有了这个库我不知道我该怎么做呢?

三,我想返回一个具有 3 个字段的结构的 complexType:

a) 代码 b) 消息 c) Exception:这里不知道怎么把异常返回给wsdl。

对于这 3 个字段,我认为在我创建的 responseData 类中,但我无法返回这种类型的数据。我知道我在问 3 个问题,但我正在阅读 spyne 的所有文档,但我没有找到任何问题。

【问题讨论】:

    标签: python django soap wsdl spyne


    【解决方案1】:

    首先,感谢您试用 Spyne!

    答案:

    1. 试试

      return ResponseData(codResultado=1234, message="Hello!")
      
    2. _out_response_name 传递给@rpc

    3. 不要发明你的,而是使用内置的Fault 类。

    Spyne 文档很糟糕,是的,但它们并没有那么糟糕。阅读它们:)

    Spyne 也有一个邮件列表:http://lists.spyne.io/listinfo/people

    第,

    【讨论】:

    • 非常感谢您的回答和建议。我没有看人的邮件列表,因为系统登录有点困难。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多