title: Programmatically set WCF timeout in debug mode
body: <p>I'm using WCF in communication between a server and client (both written in C#). </p>
  
  <p>In release-mode, the timouts should be set to ~20 seconds, but in debug mode I want to set them to a higher value so that I can debug/step in my code without the timeout occurring.</p>
  
  <p>I know that I can change the timeouts by modifying the app.config file. However, I've got two different bindings and 4 time out values in each so I would have to change in several places, and its easy to forget.</p>
  
  <p>To solve this, I would like to have a small #if DEBUG-section in my code which programmatically changes the timeout values to 1 hour.</p>
  
  <p>I tried to use the following code to do this:</p>
  
  <pre><code>Configuration configuration = 
         ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  ServiceModelSectionGroup serviceModel = 
         ServiceModelSectionGroup.GetSectionGroup(configuration); 
  
  BindingsSection bindings = serviceModel.Bindings;
  
  foreach (var configuredBinding in bindings.WSHttpBinding.ConfiguredBindings)
  {
   configuredBinding.CloseTimeout = new TimeSpan(0, 30, 0);
   configuredBinding.OpenTimeout = new TimeSpan(0, 30, 0);
  </code></pre>
  
  <p>but the *Timeout properties are readonly so I get a compilation error.</p>
  
  <p>I'm not fond of the idea of creating bindings from scratch programmatically. If I change some of the attributes in the app.config, I have to remember to do the same change in the code to make sure that the debug-behavior is similar to the release-behavior (except for the timeouts..)</p>
  
  <p>How to handle this?</p>