coffee, black   no sugar


20061201 Friday December 01, 2006
Http in .Net
200612011827

I wrote a while back about my experiences with the HTTP API in .Net. Today, I sat down to debug some weird behavior in my code that uses the API and I'd like to share what I found.

My webapp, sitting in ASP.Net, is making some plain HTTP requests and also has to call happily calls some web services. Right after starting the app, everything was working fine, but after a short while I got exceptions from the .Net HTTP stack. It was unhappy that some requests timed out or that the "server unexpectedly closed the connection". I had the hunch that the persistent connection handling was causing the trouble, but without code knowledge I was just seeing Heisenbugs.

Well, I thought, if someone knows how to use this API, it must be Dare Obasanjo, the man behind RSS Bandit. And right I was. Imena! In his code's comment he points at a (no longer working, sigh) link at microsoft and to a blog entry by Jan Tielens and one by Aaron Johnson which experienced the same problems and described a solution.

Basically, persistent connection handling in .Net seems to be fragged and you need to tell the HttpWebRequest not to use any keepalive things, tweak some ServicePointManager cleanup timeouts, disable the use of 100-Continue, skin a cat and throw some pinches of salt over your left shoulder. Then it seems to work. (Read the post by Aaron for some code snippets.)

Then I found also at Microsoft a knowledge base article which explains all you need to know. This article does not show up when you search at Microsoft, I had to use Google.

Technorati Tags: , , , , , ,

Comments:

Comments are closed for this entry.