Wayne Molina
Wayne Molina

Reputation: 19586

How to dynamically change and persist a .NET Web Service URL?

We rely on a third party web service, and we have been given three URLs that this web service can be called from by the vendor. We want to implement some kind of rudimentary failover logic so if one URL doesn't work, we have other URLs to try - the vendor themselves do not do this so it's up to us in our application code.

The "default" URL is stored in the project's config file, and various parts of the application use it. To be able to implement failover I would need to update the URL that's used (to the first URL in my list that connects successfully) and persist that URL for the entirety of the application so all the other parts can make use of it, as opposed to just setting it for a specific request. In an ideal situation this URL wouldn't change frequently but if one URL is down, it would have to dynamically be changed to use another URL that's verified to work and possibly be changed back at a later time if the new URL is down and the old URL is back up (I hope that makes sense!).

Is there a simple way to do this, or should I just add the checking logic to the method(s) where the web service is being called?

Upvotes: 0

Views: 203

Answers (1)

Anton Gogolev
Anton Gogolev

Reputation: 115769

You're mixing concerns here. To me, your application should not implement any failover logic whatsoever. Rather I'd go and implement a local web service proxy your app will be talking to. This proxy will be the component responsible for failing over and rotating target web services:

Your App ---> Proxy WS ---> The Internets ---> Target WS #1
                                           +-> Target WS #2
                                           +-> Target WS #3

Upvotes: 1

Related Questions