0

I have 2 websites with an identical web service. For web service SampleService, I would like to know how to choose which web server to choose from.

  • Web service: "SampleService"
  • Web reference: "SampleWebReference"

Web service url:

Q: How do I programmatically change which site the web reference references based on user selection?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
cabgef
  • 1,398
  • 3
  • 19
  • 35
  • possible duplicate of [Is it possible to change the properties of a WebReference in run-time?](http://stackoverflow.com/questions/211510/is-it-possible-to-change-the-properties-of-a-webreference-in-run-time) – John Saunders Nov 22 '12 at 17:46
  • possible duplicate of [ASMX: setting the website at runtime](http://stackoverflow.com/questions/2997885/asmx-setting-the-website-at-runtime) – KyleMit Aug 19 '14 at 15:14

1 Answers1

6

Click on your web service and in the properties window set the URL behaviour to Dynamic.

Then to set the url in code:

SampleWebReference reference = new SampleWebReference();
reference.Url = "http://www2.samplesite.com";
djdd87
  • 67,346
  • 27
  • 156
  • 195