views:

71

answers:

1

We have a series of web services that live in different environments (dev/qa/staging/production) that are accessed from a web application, a web site, and other services. There are a few different service areas as well. So for production, we have services on four different boxes.

We conquered the db connection string issue by checking the hostname in global.asax and setting some application wide settings based on that hostname. There is a config.xml that is in source control that list the various hostnames and what settings they should get.

However, we haven't found an elegant solution for web services. What we have done so far is add references to all the environments to the projects and add several using statements to the files that use the services. When we checkout the project, we uncomment the appropriate using statement for the environment we're in.

It looks something like this:

// Development
// using com.tracking-services.dev
// using com.upload-services.dev

// QA
// using com.tracking-services.qa
// using com.upload-services.qa

// Production
// using com.tracking-services.www
// using com.upload-services.www

Obviously as we use web services more and more this technique will get more and more burdensome.

I have considered putting the namespaces into web.config.dev, web.config.qa, etc and swapping them out on application start in global.asax. I don't think that will work because by the time global.asax is run the compilation is already done and the web.config changes won't have much effect.

Since the "best practices" include using web services for data access, I'm hoping this is not a unique problem and someone has already come up with a solution.

Or are we going about this whole thing wrong?

Edit: These are asmx web services. There is no url referenced in the web.config that I can find.

+1  A: 

Make one reference and use configuration to switch the target urls as appropriate. No reason to have separate proxies at all.

Wyatt Barnett
That sounds like a great idea. Umm... how do I do that?
Jere.Jones
Exactly how depends on what sorts of proxies (ASMX vs WCF) you are using. In either case, there should be some stuff in your application's configuration generated when you created the proxy. Adjust the url in that as appropriate. You might have to set the dynamic property on the proxy to true and regenerate. You can also generally supply the configuration information in code if you want to do it that way or have your own config infrastructure.
Wyatt Barnett