How to reference a reference type?

  • Thread starter Thread starter Jared
  • Start date Start date
J

Jared

Hi

I have two web services running in different locations. I would like to
write some code to automatically fail over to the secondary if the
primary fails.

Rather than duplicating all my code I was hoping there was a simple way
to reference different type in a generic way. Is is possible to enter a
type as a string and convert it somehow?

My web services sit under the App_WebReferences folder. One is called
WebService1 and the other is called WebService2. Both have a service
called security with a number of methods. Both are currently referenced
using the following syntax;

WebService1.Security wsSec = new WebService1.Security();

This is wrapped in an if statement that uses an integer to determine
which one to use (I have already checked that the web services are
running as Session Start).

I want to be able to create a generic type which can reference either
web service. I don't want to have to wrap every piece of code that
references the web service in an if statement. This is made especially
difficult, as some of the web service methods use structs as well.

I have looked at delegates, but they only seem to work for methods.

Any help would be appreciated.

Thanks

Jared
 
Can't you just have a single reference, and update the Url property at
runtime when it falls over?

Marc
 
From the description of your problem, it sounds like the Singleton
pattern would help you out here. Make an additional method on the
singleton that would "switch" the instance returned from the singleton.
This way you have a central access point of your webserver instance.

Heres the singleton description :
http://www.dofactory.com/Patterns/PatternSingleton.aspx

Would that work?

Sean
 
Back
Top