Geeks With Blogs
Ignus Bezuidenhout blog

We call our web services through TAM.  Of course this is never done in development so when we started testing one of our applications the other day we got the following error: “The underlying connection was closed: A connection that was expected to be kept alive was closed by the server”.  This happened on subsequent calls to services through the TAM from our .Net application and did not seem to happen from the Java side.  The first call will work fine but the second or third call will fail with the above mentioned error message.

 

We at first used the approach as described by Microsoft (http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599) and did a proxy class for every one of our service calls in which we then set the Keepalive property to False.  Here is the code:

public class MyServiceProxy : MyService

{

protected override System.Net.WebRequest GetWebRequest(Uri uri)

{

System.Net.HttpWebRequest webRequest =

(System.Net.HttpWebRequest)base.GetWebRequest(uri);

webRequest.KeepAlive = false;

return webRequest;

}

}

 

This solved the issue but we got a little concerned about performance since we will force the connection close after every call.  We also are very close to UAT on our application and did not want to make significant code changes to all our service calls.

 

After some digging around we found a timeout setting for keeping connections alive on the TAM server.  This setting was set to 5 seconds on the server.  The corresponding setting inside the .Net framework (MaxServicePointIdleTime setting in ServicePointManager static class) was set to 100 seconds.

 

This change is done on a global level and we have decided to do that at session start in our web application.  This setting is in milliseconds so we now have that set to 30000.

 

We have not seen the error again and we need to do load testing now but all indications are that this will be a good solution.

 

Posted on Wednesday, August 9, 2006 11:52 AM VB.Net , ASP.Net , C# | Back to top


Comments on this post: Web Service Call Error: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server

# re: Web Service Call Error: The underlying connection was closed: A connection that was expected to be kept alive was closed by
Requesting Gravatar...
Hey,

I have seen the same issue in some of our implementations and I am just curious if I read your blog correctly. To solve the problem you decreased MaxServicePointIdleTime to 30 seconds. Thus, the idle connections are closed more often.

It would be cool if you could elaborate on your further findings :) Thanks a lot!
Left by vman on Mar 06, 2008 12:34 PM

# re: Web Service Call Error: The underlying connection was closed: A connection that was expected to be kept alive was closed by
Requesting Gravatar...
Thanks for your share.
This article help us much.
Left by Rely on Dec 07, 2009 3:48 AM

Your comment:
 (will show your gravatar)


Copyright © Ignus Bezuidenhout | Powered by: GeeksWithBlogs.net