这是示例服务
NS = 'my_app_namespace'
class MyMethodRS(ComplexModel):
__tns__ = NS
Version = XmlAttribute(Unicode)
class MyService(ServiceBase):
__tns__ = NS
@srpc(Unicode, _returns=MyMethodRS, _out_variable_name='MyMethodRS')
def my_method(foo):
response = MyMethodRS()
response.Version = '1.0'
return response
# and then application will be created and starged as wsgi app
然后我发布一个请求
<?xml version='1.0' encoding='UTF-8' ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<my_method xmlns="my_app_namespace">
<foo>bar</foo>
<my_method>
</soap:Body>
</soap:Envelope>
我得到了
<?xml version='1.0' encoding='UTF-8' ?>
<senv:Envelope>
<senv:Body>
<tns:my_methodResponse>
<tns:MyMethodRS Version="1.0" />
</tns:my_methodResponse>
</senv:Body>
</senv:Envelope>
我不希望将响应包装到my_methodResponse
. 我试图添加_body_style='bare'
并@srpc
失败了
<?xml version='1.0' encoding='UTF-8' ?>
<senv:Envelope>
<senv:Body>
<senv:Fault>
<faultcode>senv:Client.SchemaValidationError</faultcode>
<faultstring><string>:14:0:ERROR:SCHEMASV:SCHEMAV_CVC_TYPE_3_1_2: Element '{http://www.opentravel.org/OTA/2003/05}my_method': Element content is not allowed, because the type definition is simple.</faultstring>
<faultactor />
</senv:Fault>
</senv:Body>
</senv:Envelope>
我应该如何处理?我正在尝试实现严格的 API,并且无法在我的响应中添加任何包装器。