Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to customize http connection timeout?

How to customize http connection timeout?

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shooterlily
    wrote on last edited by
    #1

    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!

    H 1 Reply Last reply
    0
    • S shooterlily

      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!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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-----

      S 2 Replies Last reply
      0
      • H Heath Stewart

        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-----

        S Offline
        S Offline
        shooterlily
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • H Heath Stewart

          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-----

          S Offline
          S Offline
          shooterlily
          wrote on last edited by
          #4

          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 ?

          H 1 Reply Last reply
          0
          • S shooterlily

            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 ?

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            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, the SqlCommand.CommandTimeout, the HttpClientChannel 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-----

            S 1 Reply Last reply
            0
            • H Heath Stewart

              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, the SqlCommand.CommandTimeout, the HttpClientChannel 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-----

              S Offline
              S Offline
              shooterlily
              wrote on last edited by
              #6

              It sounds quite reasonable.Thank you!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups