I want to call a web service, but I won't know the url till runtime.
Whats the best way to get the web reference in, without actually committing to a url.
What about having 1 client hit the same web service on say 10 different domains?
I want to call a web service, but I won't know the url till runtime.
Whats the best way to get the web reference in, without actually committing to a url.
What about having 1 client hit the same web service on say 10 different domains?
Create the web reference, and convert the web service to a dynamic web service. A dynamic web service allows you to modify the Url.
You need to create the web reference now to ensure your application understands the interfaces available. By switching to a dynamic web service you can then modify the .Url property after you have initialised the web reference in your code.
service = new MyWebService.MyWebService();
service.Url = myWebServiceUrl;
You can change the Url property of the class generated by the Web Reference wizard.
Here is a very similiar question; http://stackoverflow.com/questions/125399/how-can-i-dynamically-switch-web-service-addresses-in-net-without-a-recompile
you could call your web service by a simple http Request: Example:
http://serverName/appName/WSname.asmx/yourMethod? param1=val1¶m2=val2;
if you call via Http, http response will be serialized result.
But if you use a web reference, you always can change Url, by Url property in web service proxy class. Url tipically will be stored in your web.config
I hope i help you
The only way I have found to do this, is by using wsdl.exe directly and generating the proxies without any url, then doing something similar to david's answer.