tags:

views:

32

answers:

2

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 call 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)

A: 

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.

Pieter
virtual -1. MyService is a proxy and not MyContract.
Aliostad
(Stupid question) are you sure about this? If they aren't proxies, that would mean that all memory is allocated at (1) and you should be able to test this with commenting out all lines after (1) and seeing whether it still crashes.
Pieter
+1  A: 

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.

casperOne