The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

  • Advertisements

Dynamic Class library Web References

Posted by Clayton James on August 26, 2008

I have a web application that referneces a class library project that contains web references. These web references need to be dynamic as we migrate applications from development to testing to production. When you add a web reference to a class library project and make the UrlBehaviour Dynamic (not Staic) then a app.config file is created which stores the web service location.



The problem is that the app.config file doesn’t get deployed as a separate file with your web application, so how do you make runtime updates to web service references?


Answer (one of many)

You copy the app.config settings to your web.config file. The web.config file will then provide the dynamic reference to easily change between development and production environments without recompiling any code.


For example:

You only need to copy over sections that don’t already exist in the web.config file.

– sectionGroup

– applicationSettings

        <sectionGroup name=”applicationSettings” type=”System.Configuration.ApplicationSettingsGroup, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089″ >
            <section name=”CJ.Blah.Business.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />
            <setting name=”Business_CJWS_WS” serializeAs=”String”>

To make this web reference point to the production server then all you need to do is open the web.config file and change the value “testwebserver” to “productionwebserver“.

If a new web reference is added to the class library project then a new entry will be created in the app.config file. This will need to be copied over manually to the web.config.


One Response to “Dynamic Class library Web References”

  1. Roshan Perera said

    thank you very much, it is working fine

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: