开发者

When is memory from a WCF Call Allocated?

开发者 https://www.devze.com 2023-01-20 09:40 出处:网络
I have a call to a SOAP WCF Service that returns a lot of data.More than the calling Windows Mobile Device can handle.

I have a call to a SOAP WCF Service that returns a lot of data. More than the calling Windows Mobile Device can handle.

Yet I am noticing something odd. When I make the call it looks like this:

MyContract[] myContractArray = MyService.CallToGetLotsOfDataObjects();

That does not fail. But when it iterate through myContractArray and put them into client side classes, then it fails.

At first I just said, "well, it can't handle having two copies of the data, that is just too much". But now I am wondering if myContractArray is actually holding the data after the above call. I am wondering if it is kind of like a Linq-To-SQL cal开发者_运维百科l where it does not get loaded till it is needed.

So here is my question, at what point below does the data get allocated on the client?

// Create the service 
var serviceLib = new MyServiceDataServiceLib();

//                           1 -----------------+                      
//                                              |                      
//                                              V 
MyContract[] myContractArray = serviceLib.WCFCallToGetLotsOfDataObjects();  
List<MyClass> myClassList = new List<MyClass>()

// 3 -----------------+                       +------------------ 2
//                    |                       |
//                    V                       v
foreach(MyContract myContractInstance in myContractArray )
{
   MyClass myClassInstance = new MyClass();
   myClassInstance.BigImage = myContractInstance.BigImage;
   myClassInstance.MoreData = myContractInstance.MoreData;
   myClassInstance.EvenMoreData = myContractInstance.EvenMoreData;
   myClassList.Add(myClassInstance);
}

Is it at:

  1. When the call is made to the server
  2. When I begin to iterate the list (less likely in my opinion)
  3. As I need each instance

I think it 1 or 3, but I am not sure which it is. Does anyone know?

(NOTE: I am using Visual Studio 2008 and .net 3.5. My client side is a Windows Mobile application)


The allocation for the array is handled at 1. The proxy is like any other .NET object. The array is not 'transparent' in any way nor is it sparse.

Basically, when the data comes back from the service, if it is typed as an array, the array, as well as any elements in the array are fully serialized/materialized.


My guess is that the data is allocated at the first myContractInstance.BigImage. This would be because MyContract is a proxy, but I am not sure.

You could test this by commenting out the contents of the foreach and seeing whether you still get the exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消