2014-05-19 31 views
0

一個人如何寫Spyne來處理這樣的SOAP請求的請求處理程序:如何在spyne中做平面元素陣列?

<getUsers> 
    <users> 
    <username>foo</username> 
    <username>bar</username> 
    ... 
    </users> 
</getUsers> 

我已經試過這樣:

@rpc(Array(Unicode.customize(type_name='username'), min_occurs=1, nillable=False)) 
def getUsers(ctx, users): 
    stuff 

但它產生像這樣的模式:

<xs:complexType name="getUsers"> 
    <xs:sequence> 
     <xs:element name="users" type="tns:stringArray"/> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="stringArray"> 
    <xs:sequence> 
     <xs:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="xs:string"/> 
    </xs:sequence> 
    </xs:complexType> 

如何將元素名稱string更改爲username?最好也stringArray成更有意義的東西?我的方法完全錯誤嗎?

回答

0

2.10:

SomeArrayType = Array(Unicode, min_occurs=1, 
           nillable=False, type_name='SomeArrayType') 
SomeArrayType._type_info['username'] = SomeArrayType._type_info['string'] 
del SomeArrayType._type_info['string'] 

@rpc(SomeArrayType) 
def some_call(ctx, some_array): 
    # (...) 

2.11:

from spyne import Mandatory as M 
SomeArrayType = M(Array(Unicode, type_name='SomeArrayType', 
               member_name='username')) 

@rpc(SomeArrayType) 
def some_call(ctx, some_array): 
    # (...) 

此外,如果需要的數組是非空的,則還需要的Unicode(MIN_LEN = 1,min_occurs = 1,的nillable =假)在Array內部。即:

SomeArrayType = M(Array(M(Unicode), type_name='SomeArrayType', 
               member_name='username')) 
+0

2.11將於6月初發布 –