Friday, July 14, 2006

Asynchronous WebService calls in ASP.NET: BEWARE 

Asynchronous WebService calls – the truth behind the Begin… End… functions
I’ve finally solved this one – not that the resolution makes me happy, but it’s nice to finally explain the behavior.

I ran into a funny behavior four years ago with WebService calls on the .Net platform. At that time, my idea was to launch webservice calls simultaneously against multiple backend webservices. The effect would be the pipelining of these requests.

. . .

My answer to this problem four years ago was to place synchronous requests in a worker threadpool and manage the threads – it turns out that was the right call. After looking at the behavior of .Net, it appears that they are also running these calls on background threads. When doing this, you have to be conscientious in the number of threads being used to service these requests (especially if you’re making these from within a web application or webservice).

I would have hoped the .Net implementation would have been more elegant than my thrown-together async threadpool, but it turns out that’s just not the case. Perhaps they could have used Overlapped IO with sockets available since winsock 2???

So, long and short… if you want to shotgun your webservice requests, make synchronous calls from worker threads and take the time to get that right.

Topics: Asych | ASP.NET | Webservices

Links to this post:


Comments: Post a Comment

This page is powered by Blogger. Isn't yours?