Archive

Posts Tagged ‘Dynamic Url’

Dynamic URL for web services

March 20, 2009 Leave a comment

Today one of my colleague asked a simple question: How to change the URL of a web service dynamically?

He was using visual studio 2005. And he was using the web service directly from asp.net web site.

The answer to his question is as simple as the question itself.

Just add a web reference to the web site and after successful addition of the web service to the web site, a key is created for this web service in the web site’s web.config file under AppSettings tag. The name of the key will be defaulted to the name you gave during addition of this web reference.

So when you move this web site through all the stages to production, it will be enough to just change the URL in this web.config during installation.

<appSettings>
<add key=”localhost.Service1″ value=”http://localhost:29745/Service1.asmx”/&gt;
</appSettings>

This is the same for visual studio 2008 too.