2014-04-29 26 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) 

使得进入价值确认更为严格。