How to Change Web service Address at Runtime?

会有一股神秘感。 提交于 2019-12-13 02:40:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/34563907/how-to-change-web-service-address-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!