Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a vb.net application with asynchronous web service call(s). but it throw the error "the underlying connection was closed". after google it for many hour i found the problem is to keep my connection active. How do i explicitly set the KeepAlive property to FALSE.
Posted
Updated 20-Jan-11 1:42am
v2

I found this on google (search phrase is "webservice set keepalive false") - the 2nd link among 118,000 results:

http://www.eggheadcafe.com/software/aspnet/30191651/disabling-keepalive.aspx[^]
 
Share this answer
 
Override the GetWebRequest method in your web service code

e.g
http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx[^]



e.g
http://stackoverflow.com/questions/1527407/how-do-i-prevent-my-net-soap-client-from-including-connection-keepalive-in-th[^]

C#
namespace YourNamespace
{
    using System.Diagnostics;
    using System.Web.Services;
    using System.ComponentModel;
    using System.Web.Services.Protocols;
    using System;
    using System.Xml.Serialization;
    /// <summary>
    /// This partial class makes it so all requests specify
    /// "Connection: Close" instead of "Connection: KeepAlive" in the HTTP headers.
    /// </summary>
    public partial class YourServiceNameWse : Microsoft.Web.Services3.WebServicesClientProtocol
    {
        protected override System.Net.WebRequest GetWebRequest(Uri uri)
        {
            System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
            webRequest.KeepAlive = false;
            return webRequest;
        }
    }
}
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900