0

I have arraylist of ids contains 1000 of records and this will be passed to WCF service as parameter and I get response of 1000 records. Now my requirement is to break the 1000 into 10 chunks and call the service 10 times. How can I do this in c# asp.net client?

Example: suppose I have 150 ids to be passed, in this case 100 ids in one function call and 50 should be in second call. Like this if I have 270 ids then 100, 100 and 70 three chunks to be created and three call to be made for the service.

The code I am using right now is pasted below and in this code i am passing all the ids ata a time

ArrayList myArrayList = new ArrayList();

if (parsedData.Count > 0)
                {
                    foreach (var item in parsedData)
                    {
                        myArrayList.Add(new Identifier() { Id = item.First() });
                    }
                }

ServiceReference.CustomerProfileServiceClient clientObj = new ServiceReference.CustomerProfileServiceClient();

var responseObj = clientObj.GetProfiles( myArrayList.ToArray(typeof(Identifier)) as Identifier[]);

Thanks

user995099
  • 129
  • 1
  • 3
  • 12
  • Not really an answer to your problem, but ArrayList's are generally seen as deprecated now. You would probably be better with a strongly typed List – Darren Young Jan 05 '12 at 07:38
  • Have you reconsidered retagging this question? asp.net and wcf has no relevance here. – Morten Jan 05 '12 at 08:44

2 Answers2

1
ArrayList myArrayList = new ArrayList();
int iCount = 0;

if (parsedData.Count > 0)
                {
                    foreach (var item in parsedData)
                    {
                        myArrayList.Add(new Identifier() { Id = item.First() });
                        iCount++;
                        if (iCount % 10 == 0)
                        { 
                              ServiceReference.CustomerProfileServiceClient clientObj = new ServiceReference.CustomerProfileServiceClient();
                              var responseObj = clientObj.GetProfiles( myArrayList.ToArray(typeof(Identifier)) as Identifier[]);
                              myArrayList.Clear();
                        }
                    }
                }
Shai
  • 25,159
  • 9
  • 44
  • 67
1

I agree with Darren Young; use typed lists. Further, Use Linq. For inspiration Look at this: Split List into Sublists with LINQ.

Community
  • 1
  • 1
Morten
  • 3,778
  • 2
  • 25
  • 45