title: C# Changing Web Reference url
body: <p>I'm trying to change a web reference path depending on whether the site is live or not.</p>
  
  <p>The application settings are in the web.config</p>
  
  <pre><code>&lt;applicationSettings&gt;
  &lt;WebReferenceName.Properties.Settings&gt;
    &lt;setting name="WebReferenceName_Service_TBService"
      serializeAs="String"&gt;
      &lt;value&gt;http://localhost:50711/Service.svc&lt;/value&gt;
    &lt;/setting&gt;
  &lt;/WebReferenceName.Properties.Settings&gt;
  </code></pre>
  
  <p></p>
  
  <p>I've tried the following:</p>
  
  <pre><code>Properties.Settings.Default.WebReferenceName_Service_TBService.Equals("http://www.newurl.com/service.svc");
  </code></pre>
  
  <p>which although doesn't error, checking it later, shows it hasn't changed.</p>
  
  <p>and</p>
  
  <pre><code>var config = WebConfigurationManager.OpenWebConfiguration("~/web.config");
  config.AppSettings["WebReferenceName_Service_TBService"] = "http://www.newurl2.com/service.svc";
  config.Save(); 
  </code></pre>
  
  <p>but this errors saying I don't have permissions</p>
  
  <p>Is there another way of doing this?</p>
  
  <p>I'd rather not have to use if statements all over the place, as my types are namespaced differently.
  e.g.</p>
  
  <pre><code>using (var service = new WebServiceLocal.TheWebServiceService())
  {
       WebServiceLocal.blah();
  }
  </code></pre>
  
  <p>Thanks</p>