473,847 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Dec 21 '06 #1
1 2988
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.
Jan 2 '07 #2

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

Similar topics

6
4386
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
2763
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 'System.Collections.IEnumerable.GetEnumerator()'. 'HelloWorld.A.GetEnumerator()' is either static, not public, or has the wrong return type. class A : IEnumerable<string>
2
19867
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", etc. would like to know how implement my generic GetEnumerator to yield return an interface to IEnumerator<T>. I am getting a compile error that reminds me a lot of C++ template programming. thanks,
2
7367
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... generic<typename T> public ref class SetOfProxy : public System::Collections::Generic::IEnumerable<T>
1
2021
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 should implement IEnumerable<T>. But when I changed the return type of the GetEnumerator method the compiler said the class no longer implemented IEnumerable. IEnumerable<Thas IEnumerable as a base interface, so I had assumed that implementing...
5
11158
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(); However, I want to then select a subset of this data from within the client. I tried this: IQueryable<PenpensSubset = from p in pens select p.PenId, p.PenNumber;
3
1936
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) item.MethodOnSomeClass(); //Doesn't work
5
1800
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 allowing the developer to take full advantage of the LINQ extensions without having to start with a cast operation to a concrete type that matches the collection. I was surprised that the C# compiler was unable to resolve the type of the range...
6
14579
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? --
0
9727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10982
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10331
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9480
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7880
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5909
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.