6

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?

DevelopingChris
  • 39,797
  • 30
  • 87
  • 118

3 Answers3

8

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;
1

You can change the Url property of the class generated by the Web Reference wizard.

Here is a very similiar question; How can I dynamically switch web service addresses in .NET without a recompile?

Community
  • 1
  • 1
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
  • 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 Sep 24 '08 at 06:15
0

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
  • 4,094
  • 5
  • 28
  • 27