【问题标题】:How to model SOAP remote procedure attribute in spyne?如何在 spyne 中建模 SOAP 远程过程属性?
【发布时间】:2017-10-14 16:44:37
【问题描述】:

我有以下 SOAP 请求,我应该能够处理:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <LogoutNotification xmlns="urn:mace:shibboleth:2.0:sp:notify" type="global">
      <SessionID>
        _d5628602323819f716fcee04103ad5ef
      </SessionID>
    </LogoutNotification>
  </s:Body>
</s:Envelope>

SessionID 只是 RPC 参数。这很容易处理。

但是如何在 spyne 中为 type 属性建模? type 是“全局”或“本地”。

我目前有以下内容(并且禁用了验证以便能够简单地忽略该属性):

class LogoutNotificationService(Service):
    @rpc(MandatoryUnicode, _returns=OKType,
         _in_variable_names={'sessionid': 'SessionID'},
         _out_variable_name='OK',
         )
    def LogoutNotification(ctx, sessionid):
        pass # handle the request

为了完整起见,这里是使用的模型:

class OKType(ComplexModel):
    pass


class MandatoryUnicode(Unicode):
    class Attributes(Unicode.Attributes):
        nullable = False
        min_occurs = 1

架构是online。但是没有包含该属性的官方 WSDL。

【问题讨论】:

    标签: python soap spyne


    【解决方案1】:

    这样做的关键是使用bare 正文样式。然后您可以(并且需要)对完整的输入和输出消息进行建模。

    我的工作代码如下所示:

    class OKType(ComplexModel):
        pass
    
    
    class MandatoryUnicode(Unicode):
        class Attributes(Unicode.Attributes):
            nullable = False
            min_occurs = 1
    
    
    class LogoutRequest(ComplexModel):
        __namespace__ = 'urn:mace:shibboleth:2.0:sp:notify'
        SessionID = MandatoryUnicode
        type = XmlAttribute(Enum("global", "local", type_name="LogoutNotificationType"))
    
    
    class LogoutResponse(ComplexModel):
        __namespace__ = 'urn:mace:shibboleth:2.0:sp:notify'
        OK = OKType
    
    
    class LogoutNotificationService(Service):
        @rpc(LogoutRequest, _returns=LogoutResponse, _body_style='bare')
        def LogoutNotification(ctx, req):
            # do stuff, raise Fault on error
            # sessionid is available as req.SessionID
            return LogoutResponse
    

    关于not wrapping response 的(不是真正相关的问题)包含很好的示例,并向我展示了如何解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多