我正在使用python 2.7和django 1.9中的spyne 2.12.14 我想返回这样的响应:
?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns2:GetResponse xmlns:ns2="http://test.example.com/test">
<return>
<myHeader>
<id>1234abc</id>
<code>000</code>
<message>Success</message>
</myHeader>
<MyDetail>
<item1>myItem1</item1>
<item2>myItem2</item2>
</MyDetail>
<MyDetail>
<item1>myItem1</item1>
<item2>myItem2</item2>
</MyDetail>
</return>
</ns2:GetResponse>
</soapenv:Body>
</soapenv:Envelope>
但是得到以下答复:
?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns2:GetResponse xmlns:ns2="http://test.example.com/test">
<return>
<myHeader>
<id>1234abc</id>
<code>000</code>
<message>Success</message>
</myHeader>
<MyDetail>
<MyDetail>
<item1>myItem1</item1>
<item2>myItem2</item2>
</MyDetail>
<MyDetail>
<item1>myItem1</item1>
<item2>myItem2</item2>
</MyDetail>
</MyDetail>
</return>
</ns2:GetResponse>
</soapenv:Body>
</soapenv:Envelope>
这是我的代码:
class MyHeader(ComplexModel):
__namespace__ = 'http://test.example.com/test'
INHERITANCE = None,
INDICATOR = Sequence,
_type_info = {
'id': String,
'code': String,
'message': String,
}
class MyDetail(ComplexModel):
__namespace__ = 'http://test.example.com/test'
INHERITANCE = None,
INDICATOR = Sequence,
_type_info = {
'item1': String,
'item2': String,
}
class GetResponse(ComplexModel):
INHERITANCE = None,
INDICATOR = Sequence,
_type_info = {
'myHeader': MyHeader,
'MyDetail': Array(MyDetail, minOccurs=0, maxOccurs='unbounded')
}
@rpc(MyObject, _returns=[GetResponse], _out_variable_names=["return"])
def GetMiniStatement(ctx, MyObjectInfo):
do_something
有人可以帮忙吗?
答案 0 :(得分:0)
您需要一个非包装的数组。
删除此:
'MyDetail': MyDetail.customize(minOccurs=0, maxOccurs='unbounded')
添加此内容:
select p1.idP, p1.name, group_concat(p2.idP)
from prodotti p1
left join prodotti p2 on p1.idP = p2.prodotti_idP
group by p1.idP;
顺便说一句,您的Array定义似乎很奇怪,因为通过将 Array 类型的maxOccurs设置为大于1的值,您将创建一个未包装的未包装数组,看起来像你想要的。 (换句话说,您告诉Spyne Array类型可以出现多次,而不是内部发生的事情。)
答案 1 :(得分:0)
将我的声明更改为 'MyDetail':Array(MyDetail,maxOccurs ='unbounded',包装= False) 而且有效。