0

我们在 SOAP Web 服务中遇到了性能问题。网络服务是用 Spyne 构建的。

我认为这个问题可以通过改变接口来解决,接口只会返回必要的数据,因为我们向客户端发送了大的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.

以及更多!!

我们实现了两个接口搜索fabric和getfabric,见下图:

搜索面料:

@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,这会解决性能问题吗?

4

1 回答 1

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)

使传入的值验证更加严格。

于 2014-04-30T09:46:19.280 回答