c# - 在运行时设置服务 URL

标签 c# asmx app-config

当我添加“Web 引用”时,我们将 asmx 页面的地址提供给 visual studio。

如何在运行时设置它?

最佳答案

我会赞成其他答案之一 - 它们几乎是正确的。

using (YourService service = new YourService())
{
    service.Url = "http://some.other.url/"; 

    // Now you're ready to call your service method 
    service.SomeUsefulMethod(); 
}

如果未使用 using block 并抛出异常,则可能会泄漏网络连接等资源。

关于c# - 在运行时设置服务 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2997885/

相关文章:

Asp.net url路由捕获asmx web服务调用

wcf - 如何将大文件从 MS Word 插件 (VBA) 传输到 Web 服务器?

c# - 为什么 config.Appsettings.Settings ["MySetting"].Value 在 Windows 7 中失败,但在其他版本中没有

c# - 序列化UTC时间c#

c# - 在 Windows Phone 中使用语义缩放

c# - 如何在通用Windows平台(UWP)C#上显示音频信号?

c# - 什么是 ASP.NET Web 服务请求生命周期?

c#-4.0 - 如何使用 log4net 在 AppData 文件夹中创建文件

c# - 在运行时更改默认的 app.config

c# - 'OpenFileDialog' 第一次不取值