如何在运行时更改Web服务地址? [英] How to Change Web service Address at Runtime?
本文介绍了如何在运行时更改Web服务地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在wpf应用程序中使用的是Web服务. 并将其"URL行为"设置为动态",因此我在app.config文件中有一个条目,如下所示:
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>
我需要动态更改服务器地址,例如从192.168.35.28
更改为192.168.35.26
.
问题是:如何在运行时更改<value>
标记的内容?
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?
非常感谢:)
推荐答案
您尝试过吗?
var service = new MyApp.OnlineUsersService();
service.Url = "http://192.168.35.28/OnlineUsersService.asmx";
如果您实际上是在为其他路径指定网址,那么我建议在打包之前使用配置转换(App.Release.Config)更改网址.
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.
这篇关于如何在运行时更改Web服务地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文