Peter,
Thanx for the response.
I have a stored procedure which I execute via a DataReader. The method that
reads the data from the stored procedure returns structs with the "yield
return" method as a generic IEnumerable for example:
public IEnumerable<Cus tomerStructGetC ustomers()
{
IdataReader Mydata = DataLayer.Execu te("ProcedureNa me");
while (Mydata.Read())
{
yield return new CustomerStruct( MyData.GetStrin g(0).......);
}
}
I call this method from within a web service. The problem is that a web
service cannot expose IEnumerable<Cus tomerStruct>, so I have to use a
CustomerStruct[].
In order to get the results from the GetCustomers method returned, I first
have to get all the CustomerStruct structs in a single collection, which
takes up to much memory and makes things slow.
I would prefer a way to start building up the resulting soap message that
goes to the client while I am iterating through the method's resulting
IEnumerable.
If this can be done, it means that I will always have only one
CustomerStruct and one datarow in memory at a given time, which will be much
faster than having to collect all CustomerStruct' s first.
I am currently doing this as follows, but it is to slow:
List<CustomerSt ructResult = new List<CustomerSt ruct>(GetCustom ers());
return Result.ToArray( );
I hope this makes more sense now.
"Peter Ritchie [C# MVP]" wrote:
No, IEnumerable only provides a means to enumerate, not convert (hence the
"Enumerable "). IEnumerable is merely an interface to an implementation which
probably has something you can use to convert to an array. Where are you
getting this IEnumerable interface instance? Are you implementing this
collection yourself or are you retrieving it from an 3rd party method?
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"FrancoisViljoe n" wrote:
Hi there,
Does anybody know how to return the results of an IEnumerable<typ eas an
array of the same type i.e type[] in a web service call without first having
to collect all elements in the IEnumerable<typ eand storing it in memory
first?
This question is really about optimizing large collections of data returned
by web services. If it is possible to loop through the IEnumerable<typ e>
with a "foreach" and somehow start formatting the soap response already,
there should be a fair amount of memory and time saved. We are currently
running into timeouts and outofmemoryExce ptions because building up a
collection of types in a list<typecannot handle the load.
I tried to do this using the Context.Respons e and the formatting the SOAP
message myself, but the result of the call on the client returns a null
value. I suspect that this is because it expects a compressed SOAP message.
I also tried to compress the response using GZipStream, but to no avail.
Any help on this would be greatly appreciated.