Code to handle WebService URL being redirected to new URL

I have a VB.Net windows client code that is connecting to a webservice URL, say:

The URL is stored in the app.config file. Then a Redirection is setup in the IIS Webserver, say the above URL is now being redirected to a new URL:

My VB project has a Web Reference to myProject.WebService, so it is reference thru-out the application.
Currently my code stands like this:

        Dim proxyWebService As myProject.WebService.SampleService
        'Reading off the app.config
        proxyWebService.Url = System.Configuration.ConfigurationManager.AppSettings("SampleServiceURL")

            ' then I call any Web Methods on the Webservice
            strOutputXML = proxyWebService.mySampleMethod()
How can I make my code flexible to handle this future change of the URL, without manually changing the app.config value.
Who is Participating?
conrabaAuthor Commented:
If the URL changes, then that has to be communicated to the application somehow.  So your only options are hardcoding it or retrieving it from a settings store.  

In our applications, we find the app.config file too cryptic for client consumption so we use our own equivalent and provide GUI functions to configure it.  You could do the same or even provide a GUI to configure the app.config file.

If you use your own settings store for the url,  then you need to instantiate your web service (which will read the url from the app.config file) and then set the Url from your own settings store.

We created a simple Application factory class for the client application which generated configure instances of each web service using settings retrieved from our own settings file.

Hope this is useful.

conrabaAuthor Commented:
It is a windows app w/c consumes the webservice, though I forgot to mention this is deployed to disconnected laptops w/c only gets internet connection only when plugged-in, just to convey a manual update to such close to a hundred users is a nightmare.  

I see where you are going at but to the new URL is basically unknown since the environment hasn’t been created yet (might be next year), hence the need of flexibility on code.

I figured, handling a redirect first to obtain a webservice connection will allow them to continue, and behind the scenes will be any application update firing-up, including an app.config update. Then for a certain point, the original URL will then seize to exist.
Regardless, the requirement is that the windows client needs to access one webservice URL.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

conraba, that's a bad solution.
you should be setting webservice.Url property to dynamically change the destination.
conrabaAuthor Commented:
@meraydin2, you are exactly correct,  the end goal was to assign the  new URL value. If you read carefully the solution on the other link, it was trying to get the new URL. Although it did not show assigning the new URL, it clearly shows how to get the new one.

If you have a better solution, please post it here so there is an alternative.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.