473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Returning data contained in Ienumerable<type> as type[]?

Hi there,

Does anybody know how to return the results of an IEnumerable<typeas an
array of the same type i.e type[] in a web service call without first having
to collect all elements in the IEnumerable<typeand 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<type>
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 outofmemoryExceptions because building up a
collection of types in a list<typecannot handle the load.

I tried to do this using the Context.Response 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.
Dec 21 '06 #1
1 2921
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<CustomerStructGetCustomers()
{
IdataReader Mydata = DataLayer.Execute("ProcedureName");
while (Mydata.Read())
{
yield return new CustomerStruct(MyData.GetString(0).......);
}
}

I call this method from within a web service. The problem is that a web
service cannot expose IEnumerable<CustomerStruct>, 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<CustomerStructResult = new List<CustomerStruct>(GetCustomers());
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#
"FrancoisViljoen" wrote:
Hi there,

Does anybody know how to return the results of an IEnumerable<typeas an
array of the same type i.e type[] in a web service call without first having
to collect all elements in the IEnumerable<typeand 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<type>
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 outofmemoryExceptions because building up a
collection of types in a list<typecannot handle the load.

I tried to do this using the Context.Response 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.
Jan 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Doug Dew | last post by:
This won't compile: using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>; namespace MyNamespace { public class MyClass<T> : IEnumerable<T> { // Appropriate stuff here }
10
by: jcc | last post by:
Hi guys, I'm a newbie to C#. My Visual Studio 2005 failed to compile the following code with error as 'HelloWorld.A' does not implement interface member...
2
by: Steve Richter | last post by:
very confused on how to implement the IEnumerable and IEnumerator interfaces on a generic type. I understand I should just use a foreach loop in the GetEnumerator method and use "yield return",...
2
by: Fred Heida | last post by:
Hi, i'm trying to (using managed C++) implment the IEnumerable<Tinterface on my class.. but have a problem with the 2 GetEnumerator method required.... what i have done is... ...
1
by: =?Utf-8?B?UElFQkFMRA==?= | last post by:
Something I found surprising this week involves the IEnumerable<Tinterface. I have a class that I wrote a couple of years ago which implements the IEnumerable interface. This week I realized it...
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
3
by: Peter Morris | last post by:
I've given this interface some thought, the benefits to using it seem to be 01: I can use "var" in a foreach //Works List<SomeClasslist = new List<SomeClass>(); foreach(var item in list)...
5
by: Anders Borum | last post by:
Hello I'm developing an API with a number of concrete collections that inherit from an abstract collection hierarchy. Each inheritance level provides an implementation of IEnumerable<T>, thus...
6
by: A.Rocha | last post by:
Hi, I need save to text file a List<type>, but i dont wont serialize. // List<mytypemyList = new List<mytype>(); anyone can help me? --
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.