Home > ASP.NET, Web Service > Dynamic URL for web services

Dynamic URL for web services


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.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: