如何在spyne中建立SOAP远程过程属性的模型?

如何在spyne中建立SOAP远程过程属性的模型?

问题描述:

我有以下的SOAP请求,我应该能够处理:如何在spyne中建立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。

这个关键是使用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包含良好榜样,教我如何解决这个问题。