title: Change a web service URL at runtime
body: <p>I am developing an application that will connect to various Web services according to the user's location .</p>
  
  <p>For example :</p>
  
  <p>If the user are in the city "A", the application will connect to the Web service: "192.168.1.1:8010", if he goes to the city "B", will connect to "192.168.1.1:8020", in the city "C" will be "192.168.1.1:8030" , and so on.</p>
  
  <p>The IP address is always the same , what changes is the port number.</p>
  
  <p>Simple thing huh? Yeah, but I can't find a way to make it work at runtime!</p>
  
  <p>When I change the " URL" parameter(myWS.Url) of the Web service("URL Behaivor == Dynamic") at runtime, the server only returns null , changing the parameter to it's original value, the communication is restored . </p>
  
  <p>Same thing if the change is made before compilation, compile to the city "A" , works only in the city "A" , compile to the city "B" , works only in the city "B".</p>
  
  <p>The application is originally developed for Windows CE 5.0 using VS2008 and CF3.5, but even in VS2013 with . NET Framework 4.0 and Windows Seven the "problem" still happens.</p>
  
  <p>Has anyone experienced this?</p>
  
  <p>As requested, here is a small part of my code:</p>
  
  <pre><code>WSR.WSR myWS = new WSR.WSR();
  
  //WSR added as a Web Reference
  
  if (City_A)
  {
      myWS.Url = "http://192.168.1.1:8010/WSR.apw";
  }
  else
  {
      myWS.Url = "http://192.168.1.1:8020/WSR.apw";
  }
  </code></pre>
  
  <p>The solution purposed in this topic(<a href="https://stackoverflow.com/questions/2810967/what-should-be-modified-to-change-the-url-of-a-web-service-in-c">What should be modified to change the URL of a web service in C#?</a>) doesn't work for me because, as I said, when I changed the "URL Behavior" property no entry point was created in my app.config file.</p>
  
  <p>Here is the app.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="TrocaWebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;startup&gt; 
  
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/&gt;&lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings /&gt;
          &lt;client /&gt;
      &lt;/system.serviceModel&gt;
      &lt;userSettings&gt;
          &lt;TrocaWebService.Properties.Settings&gt;
              &lt;setting name="TrocaWebService_WSR_WSR" serializeAs="String"&gt;
                  &lt;value&gt;http://192.168.1.1:8010/WSR.apw&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/TrocaWebService.Properties.Settings&gt;
      &lt;/userSettings&gt;
  &lt;/configuration&gt;
  </code></pre>