Varad, The .NET Guy!

Exploring the excitement of Microsoft .NET and much more..

Help: How to Configure Web Services URL?

We are developing an Intranet Web Application that consumes about 7 to 8 internal web services [.NET and J2EE] for different transactions. We host the web services and our application in different environments viz DEV, Test, UAT etc.

The web references for these web services are set to Dynamic and Web Services URL is dynamically taken from the Web.config file. Now we want to have a standard web.config file in order to keep our deployment to any of the environment the same. When we are in DEV environment we need to access the Web Services that were hosted in DEV and vice versa for other environments. The problem now is we cannot have a common Web.config file that has the URL for the web services, that is being used by our web reference. Because when we move the code from DEV to Test to UAT etc, we need to make changes to web.config file. The pain is there are 4 to 5 servers involved in Test and UAT environments and we have to manually edit the web.config file in all the servers to point to specific web services URL.  If the web application and web services are hosted on the same servers, Is there any way to dynamically configure the URL for web services in web.config?

For e.g,

In Test environment we have 5 servers (test01.myserver.net, test02.myserver.net, test03.myserver.net, etc) both the web application and web services are hosted on the same servers. The web application in test01.myserver.net has to access the web service hosted in test01.myserver.net and vice versa for other servers. In this case I need to manually edit the web.config in all the 5 servers and change the Web Services URL of the 7 services to point the respective URL.

We are not allowed to keep the web services in a single server, In test environment both the web application and web services has to exist in the same server. But these servers are load balanced.

Is there any way to dynamically configure the web.config file? Like using host files or environment variable..

It would be great if anyone throw me some light to resolve this.

Thanks!

 

 

Posted: Feb 26 2006, 02:02 PM by Varad | with 6 comment(s)
Filed under:

Comments

Melvin Lee said:

You can make use of the file attribute of the appSettings element if this is where you manage the urls to your webservices.
Like you I have different environments (DEV, Test, Production). For each of these environment I create a separate file where I keep all the custom application settings (e.g. url to the webservices)
Every time I deploy my apps to an environment I only have to set the file attribute to point to the correct file. Check the MSDN documentation of the <appSettings> element for more info about the file attribute.
There is one disadvantage using this approach. If you make changes to one of the custom app settings files, the web app is not automatically restarted like if you make changes to web.config. You have to "touch" the web.config file to have the new settings loaded into memory.
# February 26, 2006 4:10 PM

Jeremy said:

I'll give you two possibilities -->

web.config files are just xml. If you're building with NAnt you can use the <xmlpoke> task to overwrite the url value to create different deployment copies.

Or, we do something like this with StructureMap (http://structuremap.sourceforge.net) that attaches dependencies. You can use StructureMap out of the box to create machine specific overloads to find the default instance for the web proxy class.
# February 26, 2006 7:33 PM

Varad said:

Melvin & Jeremy, Thanks a lot for your response. I will try them out..

Thanks again!
# February 26, 2006 9:11 PM

John Walker said:

If these are .Net 2.0 projects then you could use the new Visual Studio 2005 Web Deployment Projects. It lets you substitute parts of your Web.config files when deployed in Release mode. This has worked great for us with our projects. It's really easy to configure. Scott Guthrie has a great article on it here...

http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx

Download is here...
http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
# February 27, 2006 2:36 AM

Raj Kaimal said:


Use a Web Deployment project. It has the option to replace configuration sections.

http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
# February 27, 2006 9:32 AM

Varad said:

Thanks Raj & John. We are in .NET 1.1, Unfortunately we do not have access or allowed to run setup programs on DEV and UAT environments. So we have to do only Xcopy or Copy project.

The approach sugessted by Melvin is what we are currently using, once we move to Implementation and PROD environment we will be using the Web Deployment Project and generating msi.

Thanks for all your suggesstions.
# March 4, 2006 1:26 PM