Setting the service url at runtime

When I add the "Web Reference", we pass the address to the asmx page of the visual studio.

How can I set this at runtime?

+3
source share
3 answers

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();
+5
source

I would support one of the other answers - they are almost true.

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

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

If the block being used is not used and an exception is thrown, then resources such as network connections may be skipped.

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

Source: https://habr.com/ru/post/1749031/


All Articles