我正在使用 WCF 和“ref”参数编组列表,并且我希望能够设置容量。
一些背景。我使用 ref 编组 2 个列表,以便调用函数可以通过在调用之前进行初始化来确定它感兴趣的列表。
因此,对 null 的快速测试使服务能够对列表执行某些操作。这一切都很好。
但我想;我知道列表中将有 100~ 项,因此设置初始容量是一个好主意,但是当我在调用函数中这样做时,它会在 WCF 服务中设置回 0。
有什么线索吗?
非常感谢。
编辑:想一想 - 这确实很有意义,不是吗。任何通过设置初始容量而分配的资源都必须(浪费地)进行整理,然后重新水化/分配。
我认为第二个参数具有大小或只是硬编码它是有序的。
I am marshalling a List using WCF and an 'ref' parameter and I want to be able to set the capacity.
Some background. I am marshalling 2 List's using ref so that the calling function can determine which List it is interested in by initialising prior to the call.
Thus a quick test for null enables the service to do something with the list. This all works fine.
But I thought; I know there is going to be 100~ items in the list so setting an initial capacity is a good idea but when I do so in the calling function it is set back to 0 in the WCF service.
Any clues?
Thanks muchly.
EDIT: Thinking about it - this does make an enormous amount of sense does it. Any allocated resources from setting an initial capacity would have to be (wastefully) marshalled and then rehydrated/allocated.
I think a second parameter with a size or just hard coding it is in order.
发布评论
评论(1)
WCF 按值传递所有数据。它从不通过引用传递值。集合作为数组传输,因此除了包含的数据之外不会传输任何其他信息。标记为 ref 和 out 的参数仅定义参数传输的方向,并指示代理使用反序列化数据填充现有实例(在 ref 的情况下) >)。
如果您想传输某些信息(例如容量),则必须在单独的参数中传输它,并在服务中使用它来限制返回数据的数量。
WCF passes all data by value. It never passes values by reference. Collections are transfefred as arrays so no additional information except contained data are transferred. Parameters marked as
ref
andout
only defines which direction is the parameter transfered and also instruct proxy to fill existing instance with deserialized data (in case ofref
).If you want to transfer some information like capacity you must transfer it in separate parameter and use it in service to limit number of returned data.