Tuesday, January 23, 2007

.Net thingies i just found out

.Net thingies i just found out
(and all other people probably already know )

Dynamic Web Service References
In most ASP.net applications today, the webservice is called through a datalayer (DAL).
The DAL project is mostly a C# class library project. When you add a webservice reference, it creates a new application setting in the app.config of this project. The setting holds the url to the webservice. This setting is used during development.

However when you install the application to a test or production environment, you would like this setting to be variable. This is possible by simply copying this setting from the app.config to the web.config of the root ASP.net project.

Also make sure that the urlbehavior property of the webservice reference is set to Dynamic.

The section below is an example generated by visual studio 2005, this complete section can be copied from the app.config to the web.config.

<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Project.DataAccess.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Project.DataAccess.Properties.Settings>
<setting name="Project_DataAccess_ProjectWebservices_FuncA"
serializeAs="String">
<value>http://localhost/ProjectWebservices/FuncA.asmx</value>
</setting>
</Project.DataAccess.Properties.Settings>
</applicationSettings>

More info :

http://msdn2.microsoft.com/en-gb/library/ms246220(vs.80).aspx