How to reference a reference type?

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
 
M

Marc Gravell

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

Marc
 
S

Sean Chambers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top