Setting the service URL at runtime

老子叫甜甜 提交于 2019-11-27 04:48:14

问题


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?


回答1:


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();



回答2:


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.




回答3:


YourWebService service = new YourWebService();
service.Url = "http://www.example.com/YourWebService.asmx";
service.CallMethod();


来源:https://stackoverflow.com/questions/2997885/setting-the-service-url-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!