Search code examples
c#web-servicesasmxapp-config

How to Change Web service Address at Runtime?


I'm using a webservice in my wpf application. and set it's URL Behavior to Dynamic, so I have an entry in app.config file like below :

<MyApp.Properties.Settings>
  <setting name="MyApp_WebReference_OnlineUsersService" serializeAs="String">
    <value>http://192.168.35.28/OnlineUsersService.asmx</value>
  </setting>
</MyApp.Properties.Settings>

I need to change server address dynamically, for example from 192.168.35.28 to 192.168.35.26.
Question is : how can I change the contents of <value> tag at runtime?

thanks alot :)


Solution

  • Have you tried this?

    var service = new MyApp.OnlineUsersService();
    service.Url = "http://192.168.35.28/OnlineUsersService.asmx";
    

    If what you're actually doing is specifying the url for a different path then I'd suggest using config transformation (App.Release.Config) to change the url before packaging.