One solution is to override the GetWebRequest(Uri uri) method.
The information that led me to this decision was found on this MSDN forum post.
Method 1: modify the Auto Generated file.
Paste this snippet into the Reference.cs file that was automatically generated for you. The disadvantage of this approach is that if you ever update client web service adapters (like Update Web References), you will then have to change the file again.
protected override System.Net.WebRequest GetWebRequest(Uri uri) { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri); webRequest.KeepAlive = false; return webRequest; }
Method 2. Create a partial class
Create a file and paste the following code into it. Change the namespace and class name to match your web service.
namespace YourNamespace { using System.Diagnostics; using System.Web.Services; using System.ComponentModel; using System.Web.Services.Protocols; using System; using System.Xml.Serialization;
Notes
This approach may work if you are not using WSE. I managed to insert this method above in a webservice class other than WSE ... which extends System.Web.Services.Protocols.SoapHttpClientProtocol . From my testing, it turned out that this did not include any Http connection string at all, where when I did it inside the WSE class (which was obtained from Microsoft.Web.Services3.WebServicesClientProtocol ), it included the "Connection: Close" line. According to this site on KeepAlive HTTP :
According to HTTP 1.1, the official system keepalive method is different. All connections are kept alive, unless otherwise indicated with the following heading: Connection: close
So, although it can no longer include KeepAlive in the header ... I think in HTTP1.1 it is considered the default.
blak3r
source share