I'm creating a .NET application that uses a web service. I need set the connection http header to "closed" in the request to that web service. I've been Googling this for a day but have not been able to get anything to work.
My best effort is the code below, which attempts to override the GetWebRequest method to add the header. This appears to fail - I place a breakpoint in it, and when I run my application, the breakpoint is never hit and the connection header does not appear to be set (I'm evaluating this not by viewing the http header but by the behavior of the system handling the web request).
Some information: when I added the web reference, using Visual Studio, I right-clicked on the project in the solution explorer, chose "Add Service Reference", "Advanced", then "Add Web Reference".
namespace System.Net
{
public class MyHttpProtocol : SoapHttpClientProtocol
{
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
webRequest.Headers.Add("connection", "closed");
return webRequest;
}
}
}