Geeks With Blogs
Shailen Sukul blog
Intermittent Web Services Error

I have a proxy class that performs a large number of calls on a web service.
It fails intermittently with the following error:

System.Net.WebException: The request failed with HTTP status 401:
Unauthorized. at System.Web.Services.Protocols.SoapHttpClientProtocol.
ReadResponse(SoapClientMessage message, WebResponse response,
Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke
(String methodName, Object[] parameters)

To fix this, you should disable the Keep Alive feature on IIS and the proxy class.

Disable Keep Alive in IIS
To disable go to the Web site tab of the Web site properties window and uncheck the Keep Alive options.

Disable Keep Alive in Proxy
You need to override the default handling of WebRequest as shown below:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
System.Net.HttpWebRequest webRequest =
(System.Net.HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;

More Information on Keep Alive
Keep alive keeps the connection open across multiple requests.
To find out more, see:

Posted on Friday, April 7, 2006 10:40 PM .Net Oddities | Back to top

Comments on this post: Intermittent Web Services Error

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Shailen Sukul | Powered by: