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]
-
mv*@spam.guard.caspershouse.com
"Morgan Cheng" <mo************@gmail.comwrote in message
news:11**********************@a26g2000pre.googlegr oups.com...
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?