Is it possible to turn off "HTTP Keep-Alive" globally in app.config?

M

Morgan Cheng

Days ago, I post a question on how to make SoapHttpClientProtocol
instance make new TCP connection for each web service request. Now, I
found how.

SoapHttpClientProtocol has a protected method GetWebRequest(System.Uri
uri) which returns a WebRequest instance. Though MSDN doesn't make
clear statement. I experiment and prove that SoapHttpClientProtocol
use this method to create HttpWebRequest for HTTP request. So, I
override this protected method in subclass of SoapHttpClientProtocol.

protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = WebRequest.Create(uri.AbsoluteUri) as
HttpWebRequest;
request.KeepAlive = false;
request.UserAgent = "It is Morgan";

return request;
}

And it works as I wish.

Now, I am considering whether there is a way to config the application
to turn off HTTP Keep-Alive globally.
Is it possible?
 
M

Mr. Arnold

Morgan Cheng said:
Days ago, I post a question on how to make SoapHttpClientProtocol
instance make new TCP connection for each web service request. Now, I
found how.

SoapHttpClientProtocol has a protected method GetWebRequest(System.Uri
uri) which returns a WebRequest instance. Though MSDN doesn't make
clear statement. I experiment and prove that SoapHttpClientProtocol
use this method to create HttpWebRequest for HTTP request. So, I
override this protected method in subclass of SoapHttpClientProtocol.

And it works as I wish.

Now, I am considering whether there is a way to config the application
to turn off HTTP Keep-Alive globally.
Is it possible?

You might want to post to a MS.Public.dotnet.webservices or
MS.public.donet.framework.aspnet.webservices.
 
M

Mantorok

AFAIK it isn't possible, you have to override the class. If you can then I
would be interested to know as I have a requirement for this.

Kev
 
N

Nicholas Paldino [.NET/C# MVP]

Morgan,

I don't believe there is a way to turn it off globally, but you can make
it so that you can change the type returned by a call to WebRequest.Create
for http/https uris. You can set the value of the <webRequestModules>
element in the config file to point to a class that implements the
IWebRequestCreate interface. You would just implement that class and have
it create a new HttpWebRequest through reflection (this is a little brittle,
as it depends on implementation details), either by getting the
ConstructorInfo for HttpWebRequest, or by calling the Create method on the
HttpRequestCreator instance through reflection (preferred). Once you get
the HttpWebRequest back in your implementation of IWebRequestCreate, you
would just set the user agent and keep alive properties accordingly before
returning the new request.
 
R

Ryan K

If the server hosting the Web Service is under your control can't you just
shut if off in IIS (or equivalent)? Is there a downside to doing it there?

Ryan




Nicholas Paldino said:
Morgan,

I don't believe there is a way to turn it off globally, but you can
make it so that you can change the type returned by a call to
WebRequest.Create for http/https uris. You can set the value of the
<webRequestModules> element in the config file to point to a class that
implements the IWebRequestCreate interface. You would just implement that
class and have it create a new HttpWebRequest through reflection (this is
a little brittle, as it depends on implementation details), either by
getting the ConstructorInfo for HttpWebRequest, or by calling the Create
method on the HttpRequestCreator instance through reflection (preferred).
Once you get the HttpWebRequest back in your implementation of
IWebRequestCreate, you would just set the user agent and keep alive
properties accordingly before returning the new request.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Morgan Cheng said:
Days ago, I post a question on how to make SoapHttpClientProtocol
instance make new TCP connection for each web service request. Now, I
found how.

SoapHttpClientProtocol has a protected method GetWebRequest(System.Uri
uri) which returns a WebRequest instance. Though MSDN doesn't make
clear statement. I experiment and prove that SoapHttpClientProtocol
use this method to create HttpWebRequest for HTTP request. So, I
override this protected method in subclass of SoapHttpClientProtocol.

protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = WebRequest.Create(uri.AbsoluteUri) as
HttpWebRequest;
request.KeepAlive = false;
request.UserAgent = "It is Morgan";

return request;
}

And it works as I wish.

Now, I am considering whether there is a way to config the application
to turn off HTTP Keep-Alive globally.
Is it possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top