winformsasmxwebservice-clientweb-reference

In winforms, how do I dynamically change the url of my web reference?


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 url:

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


Solution

  • 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";