In the HTTP Connection header, my web service client is including:
Connection: Keep-Alive
I want to disable this. After doing some research, it appears the way to do this is to set the KeepAlive member of the SoapHttpChannelOptions
class to false. But, I do not see a way to access/modify SoapHttpChannelOptions
in the webservice client class that was generated for me in Visual Studio using WSE3.0 (Web Service Enhancement.
In my case, the generated stub class extends Microsoft.Web.Services3.WebServicesClientProtocol
I've been unable to find any examples searching google and most members of the SoapHttpChannelOptions class are inherited into the WebServicesClientProtocol class...
SoapHttpChannelOptions Reference
WebServicesClientProtocol Reference
Note: I'm not trying to modify the web server. I'm trying to modify the web service client.
One solution is to override the
GetWebRequest(Uri uri)
method.The information which lead me to this solution was found on this MSDN Forum Post
Method 1: Modify the Auto Generated file.
Paste this snippet into the Reference.cs file which was automatically generated for you. The downside of this approach is if you ever regenerate the web service client adapters (ie Update Web References) you will have to then modify the file again.
Method 2: Create a partial class
Create a file and paste the following code into it. Modify the namespace and class name so they match your webservice.
Notes
This approach may work if you do not use WSE. I was able to paste the method above under the non WSE webservice class... which extends
System.Web.Services.Protocols.SoapHttpClientProtocol
. From my testing it appeared that this made it not include any Http Connection line at all where as when I did it inside a WSE class (which are derived fromMicrosoft.Web.Services3.WebServicesClientProtocol
) it then included a "Connection: Close" line. According to this site on HTTP KeepAlive:So, while it may not include KeepAlive in the header anymore... I think in HTTP1.1 it's assumed to be the default.