views:

1645

answers:

4

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?

+5  A: 

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;
why is this better than generating the proxies with wsdl.exe?
DevelopingChris
A: 

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

spoon16
answers may be similar, but its not the behavior I'm really looking for.I have a service that lives on 10 domains, and I want to poll it, on each domain, given that every domain has the same wsdl.
DevelopingChris
With the latest edit it is not a 100% dupe :)
spoon16
A: 

you could call your web service by a simple http Request: Example:

http://serverName/appName/WSname.asmx/yourMethod? param1=val1&param2=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

stefano m
get requests are not allowed on asmx by default, so plain old requests are not really helpful.
DevelopingChris
strange, i make it with full success!
stefano m
A: 

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.

DevelopingChris