How to customize http connection timeout?
-
Here is my code. HttpClientChannel channel = new HttpClientChannel(); ChannelServices.RegisterChannel(channel); try{ url = "http://"+servername+":7777"; RemotingConfiguration.RegisterActivatedClientType(typeof(MyService), url); MyService myservice = new MyService(); }catch(Exception){...} If I input an error servername,I want to know error in customized timeout such as 10 seconds or else. How? Thanks!
-
Here is my code. HttpClientChannel channel = new HttpClientChannel(); ChannelServices.RegisterChannel(channel); try{ url = "http://"+servername+":7777"; RemotingConfiguration.RegisterActivatedClientType(typeof(MyService), url); MyService myservice = new MyService(); }catch(Exception){...} If I input an error servername,I want to know error in customized timeout such as 10 seconds or else. How? Thanks!
If you looked at the SDK documentation for
HttpClientChannel
, the solution is obvious:channel.Properties.Add("timeout", _timeout in milliseconds_)
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
If you looked at the SDK documentation for
HttpClientChannel
, the solution is obvious:channel.Properties.Add("timeout", _timeout in milliseconds_)
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Are you sure? When I use the following code, channel = new HttpClientChannel(); channel.Properties.Add("timeout",10000); JIT throws System.NotSupportedException. What is your suggestion?
-
If you looked at the SDK documentation for
HttpClientChannel
, the solution is obvious:channel.Properties.Add("timeout", _timeout in milliseconds_)
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
I knew something about it. The timout is a new property that is introduced in .NET framework 1.1. I have changed my framework version to 1.1. But when I use it like the following, IDictionary props = new Hashtable(); props["timeout"] = 30000; HttpClientChannel channel = new HttpClientChannel(props, new SoadClientFormatterSinkProvider()); it seems the timeout(30 seconds) does not take effect. Why? Could you help me ?
-
I knew something about it. The timout is a new property that is introduced in .NET framework 1.1. I have changed my framework version to 1.1. But when I use it like the following, IDictionary props = new Hashtable(); props["timeout"] = 30000; HttpClientChannel channel = new HttpClientChannel(props, new SoadClientFormatterSinkProvider()); it seems the timeout(30 seconds) does not take effect. Why? Could you help me ?
No, the "timeout" property has existed even before the release of 1.0 and the documentation backs this up (plus the fact I have MS Press's "Microsoft .NET Remoting" that was written about the time 1.0 was released and mentioned it. As far as the timeout not working, are you sure it's the
HttpClientChannel
that's timing out? I just ask because we had a similar problem at work yesterday I worked on for a while where our remoting objects talk to SQL Server and communicate over HTTP since they're hosted by IIS. In that case, there were many timeouts: SQL Server's query timeout, theSqlCommand.CommandTimeout
, theHttpClientChannel
timeout (which worked, and we're using 1.0), and - in some cases - the ASP.NET worker process's timeout. You can also configure the timeout as an arbitrary attribute in the<channel>
section of your .config file (if you configure your remoting object via a configuration file). This makes it easy to change. See the docs for the element for more details.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
No, the "timeout" property has existed even before the release of 1.0 and the documentation backs this up (plus the fact I have MS Press's "Microsoft .NET Remoting" that was written about the time 1.0 was released and mentioned it. As far as the timeout not working, are you sure it's the
HttpClientChannel
that's timing out? I just ask because we had a similar problem at work yesterday I worked on for a while where our remoting objects talk to SQL Server and communicate over HTTP since they're hosted by IIS. In that case, there were many timeouts: SQL Server's query timeout, theSqlCommand.CommandTimeout
, theHttpClientChannel
timeout (which worked, and we're using 1.0), and - in some cases - the ASP.NET worker process's timeout. You can also configure the timeout as an arbitrary attribute in the<channel>
section of your .config file (if you configure your remoting object via a configuration file). This makes it easy to change. See the docs for the element for more details.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
It sounds quite reasonable.Thank you!