CJ

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

  • Past Post

  • Vistor Locations

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.

 

Question

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

<configuration>
    <configSections>
        <sectionGroup name=”applicationSettings” type=”System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ >
            <section name=”CJ.Blah.Business.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <CJ.Blah.Business.Properties.Settings>
            <setting name=”Business_CJWS_WS” serializeAs=”String”>
                <value>http://testwebserver/CJWS/MyWS.asmx</value>
            </setting>
        </RSC.ProfileCentre.Business.Properties.Settings>
    </applicationSettings>
</configuration>

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“.

Note
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.

Advertisements

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 )

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: