在运行时设置服务 URL

发布于 2024-09-04 12:59:44 字数 73 浏览 5 评论 0原文

当我添加“Web 参考”时,我们将 asmx 页面的地址提供给 Visual Studio。

我如何在运行时设置它?

When I am adding the "Web Reference" we are giving the address to the asmx page to visual studio.

How Can I set this at run time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

季末如歌 2024-09-11 12:59:44

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

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

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

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

I would have upvoted one of the other answers - they're almost correct.

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

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

If a using block is not used, and an exception is thrown, then resources like network connections can be leaked.

最笨的告白 2024-09-11 12:59:44

只需在调用任何服务方法之前设置对象的 Url 属性即可:

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

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

Just set the Url property of the object before you call any of the service methods:

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

// Now you're ready to call your service method
service.SomeUsefulMethod();
念﹏祤嫣 2024-09-11 12:59:44
YourWebService service = new YourWebService();
service.Url = "http://www.example.com/YourWebService.asmx";
service.CallMethod();
YourWebService service = new YourWebService();
service.Url = "http://www.example.com/YourWebService.asmx";
service.CallMethod();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文