How to share dynamic URLs across multiple Web Application Projects

Published Thursday, May 04, 2006 3:24 PM

I was recently asked how to configure a Dynamic URL so that it could be updated in machine.config and affect all Web Application Projects calling that Web Reference on that machine.  This is fairly straight forward in VS03 and in VS05 Web Site projects.

In both VS03 and in VS05 Web Site projects the Web Reference proxies are generated to lookup the dynamic url form the <appSettings> section of web.config

Web.config

  <appSettings>
     <add key="localhost.WebService" value="http://localhost/test/WebService.asmx"/>
</appSettings>

 

Proxy Generated:

 

        /// <remarks/>
        public WebService() 
           string urlSetting = System.Configuration.ConfigurationManager.AppSettings["localhost.WebService"];
                  if ((urlSetting != null)) {
                this.Url = urlSetting;
            }
            else {
                this.Url = "http://localhost/test/WebService.asmx";
            }
        }

 

 

Since the <appSettings> section rolls up from machine.config it's easy to put this setting in machine.config remove the entry from  web.config and you're all set.

However, in VS05 WinForm projects and Web Applicaiton Project the proxy is generated to use the  <applicationSettings> section.

 

Web.config

 

    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MainWeb.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <
applicationSettings>
        <MainWeb.Properties.Settings>
            <setting name="MainWeb_localhost_WebService" serializeAs="String">
                <value>http://localhost/test/WebService.asmx</value>
            </setting>
        </MainWeb.Properties.Settings>
    </applicationSettings>

 

 

Proxy Generated:

 

        /// <remarks/>
        public WebService() {
            this.Url = global::MainWeb.Properties.Settings.Default.MainWeb_localhost_WebService;
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }

As you can see the proxy generated is very different depending on the type of project you’re using.  If you want to specify a dynamic URL in machine.config that can be overridden in web.config.  It turns out that was very easy to do in VS03 and in Web Site projects because they simply used <appSettings>.  However with WinForm projects and WAP we now getting the settings from the System.Configuration.ClientSettingsSection. See the definition under <configSections> above. 

this.Url = global::MainWeb.Properties.Settings.Default.MainWeb_localhost_WebService; 

Because the generated proxy is assuming that the URL is coming from a configuration section named <MainWeb.Properties.Settings>, you’ll have to make sure you have one defined at the machine.config level. 

You’ll need to add these both to machine.config: 

    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MainWeb.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections> 

    <applicationSettings>
        <MainWeb.Properties.Settings>
            <setting name="MainWeb_localhost_WebService" serializeAs="String">
                <value>http://localhost/test/WebService.asmx</value>
            </setting>
        </MainWeb.Properties.Settings>
    </applicationSettings>

Once this is done your proxy will always find the value from machine.config unless overridden in web.config. 

This get’s more complicated if you’re trying to share the Dynamic URL across multiple applications.  To share a Dynamic URL across applications you’ll want to make sure that the proxy in each WAP project is using the same <applicationSettings> entry.  

The best way to do this is to create a class library project will all the Web References that you want to share.  For example I created one named WebRefLibrary.  The config entries for this library project are as follows. 

    <configSections>
        <sectionGroup name="applicationSettings">
            <section name="WebRefLibrary.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <applicationSettings>
        <WebRefLibrary.Properties.Settings>
            <setting name="WebRefLibrary_localhost_WebService" serializeAs="String">
                <value>http://localhost/test/WebService.asmx</value>
            </setting>
        </WebRefLibrary.Properties.Settings>
    </applicationSettings> 

The next step is to add these entries to machine.config.  Once that is done I can add a reference to WebRefLibrary to each of my WAP Projects.  Even with out adding anything to the web.config of those WAP they will get the dynamic URL from machine.config. 

However I can now update the web.config in any of my WAP projects to override the dynamic URL. 

    <applicationSettings>
        <WebRefLibrary.Properties.Settings>
            <setting name="WebRefLibrary_localhost_WebService" serializeAs="String">
                <value>http://localhost/Production/NewWebService.asmx</value>
            </setting>
        </WebRefLibrary.Properties.Settings>
    </applicationSettings> 

By using a Class Library project containing my Web References I’m able to share a dynamic URL across Web Application Projects and update with the URL by a single change to machine.config.

Hope this helps,
Brad.

Comments

# Michael Freidgeim said on Monday, May 08, 2006 8:21 PM

I've posted a helper class that allow me to programmatically Update Dynamic Web reference URLs Diring Installation in Visual Studio 2005
http://geekswithblogs.net/mnf/articles/77631.aspx

# cyber_demon said on Thursday, May 17, 2007 3:11 AM

Hi, how would this work with a web reference on a class library project ?

# home health care services said on Tuesday, September 11, 2007 4:52 AM

If you feel distressed because of the stupefying amount of work it involves to find what you're looking for, cheer up because you are one step closer to your goal.

# harsh said on Thursday, September 18, 2008 7:30 AM

hi

how to add a dynamically url in asp.net

i think this coding is not possible to add dynamically url

any one know then just tell me how to add dynamically url in asp.net

# nick_oracel said on Friday, December 26, 2008 8:44 PM

www.message_sitmoncac.com

# Rich said on Tuesday, August 11, 2009 7:53 AM

In a web project, it is not recomended to change the proxy file that is autogenerated since It can change at any time. From what I have seen is that in the proxy contructor, you access a config file to get the value for the url for the web service to use. Is there potential for this code to get overwritten? Or would a better approach be to derive a class of the autogenerated one and override the constructor there?

# Baka said on Wednesday, March 24, 2010 5:19 PM

Good Day. This is my first time visiting this site and I found it very informational as a whole. I am so delighted in finding your website. Help me! Looking for sites on: Large outdoor wall clock. I found only this - <a href="wall-clock.biz/.../">bulova wall clock</a>. In this gold instrument, will derive a truthful persistence of fact, where it did from and what regards it, wall clock. All of us bring we also describe also boil to enhance our chemical on average paper data or any next approach technology turn, wall clock. ;-) Thanks in advance. Baka from Burundi.

# best ad program said on Saturday, April 17, 2010 12:04 PM

Nice blog. Maybe you should try to monetize it with

http://tiny.cc/05mrc

They do have 40 days cookie duration and they pay 10-15% commisions. They'll match ads based on search query of your visitors and display relevant ads on you blog.

# usaukclassifieds classifieds said on Saturday, August 07, 2010 7:23 AM

hi this is also my first time to coming this website i see all blogs this is very nice posting good

# Hollis said on Thursday, December 23, 2010 8:18 AM

ROCKS!

Kindest Regards

<a href="alternativemedicine.org.in/acupuncture.html">Acupuncture institute</a>

# Monty said on Friday, December 24, 2010 2:34 AM

is the greatest??

<a href="http://alternativemedicine.org.in">alternative medicine</a>

# Terry Matthews said on Saturday, December 25, 2010 9:05 AM

Possibly the most interesting post I read in my life :P

<a href="www.cigars-now.com/.../a>

# Megan said on Sunday, December 26, 2010 3:15 AM

The GREATEST post I read all week...

<a href="www.cigars-now.com/.../a>

# Delmar said on Sunday, December 26, 2010 11:12 PM

Hey , I don't think so =D

<a href="www.live-girls-webcam-chat.com/">eins live playlist</a>

# Sergio said on Tuesday, December 28, 2010 2:13 AM

Great read! I want to see a follow up to this topic!?

-Yours truly

<a href="alternativemedicine.org.in/aromatherapy.html">aromatherapy school in india</a>

# Loyd said on Wednesday, December 29, 2010 2:18 AM

I need to hear  what  will change with this???

<a href="http://webreputationmanagement.info">brand reputation management</a>

# Ken Mann said on Wednesday, December 29, 2010 9:59 PM

I have to hear just what  can do with that!?

<a href="http://webreputationmanagement.info">reputation management</a>

# Jeffrey said on Saturday, January 01, 2011 12:28 AM

Quincy rocks?

-My regards,

Rosemarie

<a href="www.live-video-webcam-chat.com/webcam-chat-video.html">chat münster</a>

# Parker Cabral said on Saturday, January 01, 2011 10:32 PM

Maybe the most amazing thing I have read this month!

Reggie

<a href="www.live-fetisch-webcam-chat.com/webcam-chat-fetisch.html">online chat ohne anmeldung</a>

# Cornell said on Sunday, January 02, 2011 11:48 PM

Great post! You may want to follow up on this topic!!

-Thank you,

Pat

<a href="alternativemedicinecourse.com/.../naturopathy-courses">natural medicine courses</a>

# Benito said on Wednesday, January 05, 2011 12:27 AM

I need to know exactly what Sarah thinks with this?

Carmela

<a href="www.erotiklobby.com/">erotik community</a>

# Solomon said on Thursday, January 06, 2011 2:00 AM

I'm thrilled you wrote that???

Carissa

<a href="www.erotiklobby.com/">geschichte der gefickten nachbarin</a>

# Benita Carlton said on Sunday, January 09, 2011 4:00 AM

Kendrick ROCKS!?!

Beverly

<a href="http://www.findgroomers.com">dog grooming</a>

# Jonas said on Sunday, January 09, 2011 8:30 PM

Great blog post, been waiting for that!!!

My Regards

Mickey

<a href="http://www.gume-oblak">gume</a>

# Odessa said on Tuesday, January 11, 2011 12:33 AM

I am glad you said that :P

Lilly

<a href="www.iconiccigars.com/.../Davidoff-Millennium-Robusto-Tubos-Bx-20.html">Davidoff Millennium Robusto Tubos</a>

# Lenore Mcwilliams said on Wednesday, January 12, 2011 4:33 AM

I have to hear just what Frieda will change with that!?

<a href="www.cigars-now.com/.../a>

# Gilda said on Friday, January 14, 2011 4:53 AM

I am glad you said that :)

Deann

<a href="http://www.xxl-odskodnina.si">poravnava</a>

# Kalpatech Engineers said on Friday, January 14, 2011 7:04 AM

Thanks for submission I really very impress this blogs

# Edmond Pacheco said on Saturday, January 15, 2011 6:28 AM

Bradly fail!?!

<a href="www.cigars-now.com/.../gurkha-cigars.html">gurkha cigar</a>

# Lynda Bustamante said on Wednesday, January 19, 2011 6:38 AM

Great writing! I want you to follow up on this topic!!

Kirk

<a href="goarticles.com/.../">hydroxatone customer service</a>

# Cedric said on Thursday, January 20, 2011 10:08 AM

Could be the most influential page that I read this week!?

Burton

<a href="http://alternativemedicinecourse.com">alternative medicine course</a>

# Sydney Crockett said on Sunday, January 23, 2011 8:05 AM

The most influential topic that I have read all month :D

-Best Regards

Jessie

<a href="mizarstvo-jereb.si/.../">previjalna miza</a>

# Clarice Darnell said on Monday, January 24, 2011 10:14 AM

Hollie fail!

-Sincerest Regards,

Derek

<a href="www.gbbilder4you.com/">gb pic bilder</a>

# Christian Swanson said on Wednesday, January 26, 2011 6:19 AM

Cecil FTW!!

Carmela

<a href="www.cigars-now.com/.../cohiba-cigars.html">cohiba cigar</a>

# Rosalinda Vogt said on Thursday, January 27, 2011 4:04 AM

Could be the greatest page that I have read all year!?

<a href="www.nacht-creme.net/">neurodermitis creme"</a>

# Joan said on Sunday, January 30, 2011 6:08 AM

Great blog post, I have been looking for something like that :)

<a href="www.cigars-now.com/.../a>

# Bart Thurman said on Wednesday, February 02, 2011 10:55 AM

This is the most amazing read I have read all week?!

-Warm Regards

Damien

<a href="www.finansa-credit.com/">credit score</a>

# Coleman said on Thursday, February 03, 2011 9:49 AM

I have to hear  what Lee will do with that?

<a href="www.cigars-now.com/.../a>

# Corrine said on Friday, February 04, 2011 7:06 AM

Jonas, yea right!?

Kind Regards

Shannon

<a href="www.cigars-now.com/.../montecristo.html">monte cristo</a>

# Bettie said on Saturday, February 05, 2011 5:49 AM

Great read! You might want to follow up on this topic!!!

<a href="http://www.mandarinclassroom.com">learning mandarin chinese online</a>

# Lea Benjamin said on Sunday, February 06, 2011 3:32 AM

Great writing! You may want to follow up on this topic.

<a href="www.parketarstvo-cerkvenik.si/.../a>

# Colby said on Sunday, February 06, 2011 6:18 PM

Garth FTW...

-Warm regards

Guadalupe

<a href="www.houseofrapidcreditrepair.com/.../a>

# Octavio Preston said on Monday, February 07, 2011 4:03 PM

I am wondering  what Emilia can do with that =D

<a href="www.asparagus-soap.com/.../scrubs.html">Oatmeal scrubs</a>

# Demetrius Sears said on Wednesday, February 09, 2011 3:42 AM

Claire FTW!?

<a href="www.squidoo.com/natural-handcrafted-soap">Benefits of Natural Handcrafted Soap</a>

# Jonah Waite said on Tuesday, February 15, 2011 12:09 PM

I want to know  what Alden will do about that.

<a href="http://www.yutube.si">yutube</a>

# Dominique Roberts said on Wednesday, February 16, 2011 8:12 AM

Could be the best paper that I have read this month?!

Sincerest regards

Osvaldo

<a href="www.squidoo.com/natural-handcrafted-soap">Benefits of Natural Handcrafted Soap</a>

# Mona Mccray said on Thursday, February 17, 2011 4:52 PM

Great read! You should definitely follow up on this topic :D

Simon

<a href="www.butikonlinemurah.com/">Butik Online Murah</a>

# Sam said on Friday, February 18, 2011 10:07 AM

Maybe the most amazing post I read today?

-Thanks,

Renee

<a href="www.oregonlngpropertysearch.com/">moncler jacket</a>

# Ramiro Raines said on Saturday, February 19, 2011 8:41 AM

I want to know just what Tracy will say about this???

Larry

<a href="www.mystogie.com/.../a>

# Gregorio Godfrey said on Sunday, February 20, 2011 6:53 AM

This is the most interesting paper I have read this month :P

-Sincere regards,

Andre

<a href="www.oregonlngpropertysearch.com/">moncler jackets</a>

# Tiffany said on Monday, February 21, 2011 4:35 AM

Hey Sanford, really!!!

<a href="www.butikonlinemurah.com/">Butik Online Murah</a>

# Home Security Monitoring said on Monday, April 04, 2011 1:16 AM

Hi, Neat post. There's a problem with your website in internet explorer, would test this' IE still is the market leader and a big portion of people will miss your wonderful writing due to this problem.

<b><a href="thecancerhelp.net/home-security-strategies

">Home Security Monitoring

<a/><b/>

# awning crank handle said on Monday, April 18, 2011 1:22 PM

zsdxb retractable awnings ziqx

# jcpebtdt said on Tuesday, May 10, 2011 3:26 AM

<a href=www.hermesbirkincheap.com/>Hermes Birkin</a>

# wedcgupp said on Thursday, May 19, 2011 11:52 AM

www.hermesbirkincheap.com - Hermes Birkin Handbags

# wrvdjnsh said on Saturday, May 21, 2011 10:18 PM

www.hermesbirkincheap.com - Hermes Birkin

# azequplu said on Tuesday, May 24, 2011 8:16 AM

www.hermesbirkincheap.com - Hermes Birkin|Hermes Birkin Handbags

# lnrghres said on Wednesday, May 25, 2011 7:30 PM

www.louis-vuitton-handbags-cheap.com - louis vuitton handbags cheap

# jadrnice said on Thursday, May 26, 2011 5:15 AM

Great Article! thanks for sharing!

# rzeohugg said on Friday, May 27, 2011 3:23 PM

www.louis-vuitton-handbags-on-sale.com - Louis Vuitton Handbags On Sale

# #gepwehfewwnnick[YYIYKKIYYIYI] said on Sunday, May 29, 2011 6:14 PM

www.louisvuittonknockoffs.com - louis vuitton knockoffs|louis vuitton knockoffs handbags|louis vuitton knockoffs for sale

# afcolugs said on Sunday, May 29, 2011 6:39 PM

www.reallouisvuittonbags.com - real louis vuitton bagsreal louis vuitton bags

# rucsbrwm said on Wednesday, June 01, 2011 5:48 AM

www.hermesbirkincheap.com - Hermes Birkin Handbags

# Alex Ollivier said on Thursday, July 07, 2011 8:53 AM

Hey, cool world-wide-web web-site. I seriously came upon this on Bing, and i'm stoked I did. I'm likely to definately be revisiting correct ideal here a fantastic deal more frequently. Wish I could add on the write-up and bring just somewhat considerably far a lot more for the table, but I'am just absorbing as substantially information and facts as I can inside the second.

# buy edu backlinks said on Wednesday, July 20, 2011 10:01 PM

I think other web site proprietors should take this web site as an model, very clean and excellent user genial style and design, as well as the content. You're an expert in this topic!  <a href=edubacklinksstore.com/>buy edu backlinks</a>

# RAms said on Wednesday, January 11, 2012 8:31 AM

Thanx Dude

Its really Working

# website value said on Friday, January 27, 2012 12:11 PM

thanks for very informative info given by u

<a href="http://www.websitevaluefinder.com">website value</a>

Leave a Comment

(required) 
(required) 
(optional)
(required)