views:

106

answers:

2

I have two webservices that have exactly the same methods and signatures but point at different servers (specifically the Virtual Earth production and staging environments). I wish to switch between using the production and staging services on the basis of a config setting and don't want to repeat myself and replicate each method where I call one of the services.

So what I need in effect is to create an interface which both of the services can implement and program against that. But I don't know if this is advisable or even possible.

Or do I just need to reference one of the services and switch the url property depending on whether I want to use the production or staging environment?

+3  A: 

If I understand you right, you have ONE webservice which is deployed in production and staging environments. In this case the only thing you have to do is to switch between them via the Url property.

Prensen
+1  A: 

I just put my interfaces to wcf services into a separate assembly, and reference this assembly from the client as well as from the server.
I use this central interface for the wcf service, for mocking the wcf service, and for all clients, and can swap the connections out.

I guess you use SvcUtil to create your client classes? I don't. I have created the interfaces once, and use them to create a service using a ChannelFactory with this servicecontract.

Maybe putting your servicecontract into a separate assembly and use a ChannelFactory to create the proxy would help you?

Of course if just the service URL is changing, you can just change it in the config file.

Sam
I do the same thing. Usually manually constructed proxies, etc are the way to go.
Terry Donaghe