2014-04-29 27 views
0

我們在SOAP webservice中遇到了性能問題。這個webservice是用Spyne構建的。使用Spyne與SOAP的性能問題

我認爲可以通過改變接口的接口來解決這個問題,接口只會返回必要的數據,因爲我們向客戶端發送大的soap對象。

例子:

我們具有很多特性的面料SOAP對象,見下圖:

class Fabric(ComplexModel): 
    __namespace__ = 'vadain.webservice.curtainconfig' 
    id = Mandatory.Integer 
    "Fabric ID" 
    articleNumber = String 
    "Article Number" 
    name = Mandatory.Unicode 
    "Fabric Name" 
    color = Mandatory.Unicode 
    "Color" 
    width = Float 
    "Fabric Width" 
    widthType = WidthType 
    "Width Type" 
    supplier = Mandatory.Unicode 
    supplierId = Integer 
    "Supplier" 
    ETC. 

還有更多!

我們已經實現了兩個接口尋找面料,讓面料,見下圖:

搜索面料:

@rpc(Unicode, _returns=soap.Fabric.customize(max_occurs='unbounded')) 
def fabricsWithName(ctx, name): 
--Code to get all fabrics with name 
return fabrics 

獲取面料:

@rpc(Integer, _returns=soap.Fabric) 
def getFabric(ctx, fabric_id): 
    --Code to get fabric from ID 
return fabric 

灼熱面料的接口將返回所有織物的特性,但這不是必需的。可以更改只返回結構名稱和ID。

我該如何改變這種接口的'fabricsWithName'將只返回結構名稱和ID,這將解決性能問題?

回答

0

爲什麼不將返回值設置爲僅包含所需內容的類?

例如

class FabricLite(ComplexModel): 
    __namespace__ = 'vadain.webservice.curtainconfig' 
    id = Mandatory.Integer 

    name = Mandatory.Unicode 

# (...) 

@rpc(Integer, _returns=FabricLite) 
def getFabric(ctx, fabric_id): 
    # (...) 

您不需要更改函數體中的任何內容,Spyne會忽略其餘數據。

而且,我的getFabric簽名改成這樣:

@rpc(Mandatory.UnsignedInteger32, _returns=FabricLite) 

使得進入價值確認更爲嚴格。