Speed up process in .NET/C# - calling web-service and doing database inserts/updates inside loop

In C#, 3.5, have a for loop.  Inside the for loop, call a web-service (which takes about 2 seconds for each iteraton)   and then do couple of database inserts/updates (these take .5 secs each).  But that is only for 1 iteration.  So if I have 3000 entries, takes a real long time. Any ideas to speed this up, like asynchronous way.  What is a best-practice to solve this problem, as this is a sequential flow inside a loop.
Who is Participating?
Various things
- Consider Batch operations, like bundling a few operations in a single web-service request
- Asynchronous operations will only make your application more respnsive, but also you can issue more than one request at the same time and that may increase the throughput.
- Merge insert/update into a single operation by the use a stored proc?
As ambience has already said, you can bundle multiple calls and do the same task in a single communication across layers....be it the communication with web service.or calling stored procedures in db.
Also, look at how you can reduce the turn around time in each layer, this can be done by tuning the performance at each layer. use of multiple threads in C# code, indexes in db etc. and of course doing the asynchronous operations.
For X to Y
Call web service
Do insert /Update based on value of X

If this is the case and Insert and Update and not dependant upon the sucess or failure of webservice you can move out the webservice call out of the forloop. Create a concatincated string of values or a structure which can pass the data in bulk to the web service. same is true with the inserts and update...
One SP does it all

tapdev72Author Commented:
Its right to an extent.  Samples would have helped. Maybe question is too generic.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.