Visual Studio 2005 and Web References

Visual Studio 2005 no doubt, has been a much better version of the studio, targetting .NET Framework 2.0

When we develop Web Application and Web Services, we create both the application and web service in our local machine and hence the URL
http://localhost/WebService1/Service1.asmx would work very well in our local environment.

However, when you move your application to Testing or Production machine, the Web Service will reside on a different machine (atleast that is the purpose of using a Web Service, other than platform independence). Hence, you may require to update the Web reference URL in this scenario.

While in Visual Studio .NET 2003/2002, when you add a Web Reference, a Proxy Class is also added and you can see the code that is generated, in Visual Studio 2005, only the Disco file, Discovery file and WSDL files are added when you add a Web Reference.

The App_WebReferences folder is new in Visual Studio 2005 and whats more new is that the Web Reference URLs are by default dynamic.

In Visual Studio .NET 2003 (and earlier versions), we need to mark the Web Reference URL's URL Behaviour property to dynamic, to ensure that the URL is configurable when you deploy your application. The default property is static. So, if you leave it as such, it may lead to hardcoded Web Reference URL in the proxy classes as well as WSDL.

However, in Visual Studio 2005, the default property is dynamic. The moment you add a web reference to your application, a Key value pair is added under the App Key Settings of your web.config. Needless to mention, the key is nothing but the WebReferenceName.WebServiceName and the value is the URL for the Web Service.

This makes our job simple since after deployment, we just need to change the URL in the Web.Config file and it reflects for all the Web Reference files (disco, discomap and WSDL) created for each Web Reference.

This can be very handy in deployment situations and I really found it worth sharing..

Cheers and Happy Programming !!!

Print | posted on Tuesday, October 10, 2006 10:27 AM

Comments on this post

# re: Visual Studio 2005 and Web References

Requesting Gravatar...
I'm having a problem with it pulling in the config file setting.
I'm debugging and I've changed the app.config file to a different url for the web service.
When I check the url property it is still set to the original (default) url. The only way it seems to take my change is if I change the Settings.settings value.
Any thoughts?

Thx.
Brian VZ
Left by Brian VZ on Feb 13, 2008 5:14 AM

# re: Visual Studio 2005 and Web References

Requesting Gravatar...
Very informative post and I found it useful for learing more about visual studio.
Thanks, mig33
Left by Free Stuff on May 15, 2010 3:45 AM

Your comment:

 (will show your gravatar)