在运行时设置服务URL
当我添加“Web引用”时,我们将asmx页面的地址提供给visual studio。
我怎样才能在运行时设置它?
只需在调用任何服务方法之前设置对象的Url属性:
YourService service = new YourService(); service.Url = "http://some.other.url/"; // Now you're ready to call your service method service.SomeUsefulMethod();
我会赞成其中一个答案 – 他们几乎是正确的。
using (YourService service = new YourService()) { service.Url = "http://some.other.url/"; // Now you're ready to call your service method service.SomeUsefulMethod(); }
如果未使用using块,并且抛出exception,则可能会泄漏网络连接等资源。
YourWebService service = new YourWebService(); service.Url = "http://www.example.com/YourWebService.asmx"; service.CallMethod();
- 在类库的App.config中使用ConfigurationManager.GetSection
- App.Config中的entity framework连接字符串
- 如何在控制台应用程序中为ConnectionString定义DataDirectory以使用EntityFramework Code First Migrations
- 如何使LINQ to SQL使用在运行时修改的连接字符串?
- .NET ConfigurationManager app.config混淆
- ConfigurationManager.AppSettings使用另一个配置文件
- 如何从库中访问连接字符串
- 适用于appharbor后台工作者的App.config转换
- 阅读app.config贵吗?