【发布时间】:2015-05-12 01:52:29
【问题描述】:
当我添加“Web 参考”时,我们会将 asmx 页面的地址提供给 Visual Studio。
如何在运行时进行设置?
【问题讨论】:
标签: c# asmx app-config
当我添加“Web 参考”时,我们会将 asmx 页面的地址提供给 Visual Studio。
如何在运行时进行设置?
【问题讨论】:
标签: c# asmx app-config
我会赞成其他答案之一 - 他们几乎是正确的。
using (YourService service = new YourService())
{
service.Url = "http://some.other.url/";
// Now you're ready to call your service method
service.SomeUsefulMethod();
}
如果未使用 using 块,并引发异常,则可能会泄漏网络连接等资源。
【讨论】:
只需在调用任何服务方法之前设置对象的 Url 属性:
YourService service = new YourService();
service.Url = "http://some.other.url/";
// Now you're ready to call your service method
service.SomeUsefulMethod();
【讨论】:
YourWebService service = new YourWebService();
service.Url = "http://www.example.com/YourWebService.asmx";
service.CallMethod();
【讨论】: