I am faced with writing a WCF server running on an IIS to be consumed by other platforms on different computers. I need to return a large number of objects (serialized) to the clients. I need it to be streaming since getting all of the data from my DB and arranging it according to the cilent's requirements is a very long process, so I need the clients to be able to beging processing the results as they stream out.
After doing some reading on the subject it seems that if I use WCF with transferMode StreamedResponse I can return the objects with deferred execution and this may answer my needs.
I read the following article: http://weblogs.asp.net/cibrax/archive/2008/06/10/streaming-large-content-with-wcf-and-deferred-execution.aspx
and implemented a similar WCF to the one they describe. However I changed their code from:
for(long i = 0; i < 1000; i++) //All the customers should be read from the database
{
yield return new Customer { FirstName = "Foo", LastName = "Bar", Address = "FooBar 123" };
}
to:
for(long i = 0; i < 1000000; i++) //All the customers should be read from the database
{
yield return new Customer { FirstName = "Foo", LastName = "Bar", Address = "FooBar 123" };
}
So it would simulate a large amount of data.
I noticed that when I do this the function on the client side stalls for a number of seconds before returning the objects.
Why does this happen?
Shouldn't the data start flowing on the stream immediately?
Isn't that the point of the streaming WCF with deferred execution?
Do you have a better suggestion for my problem?