Monday, December 29, 2008

Dynamic Web Reference for ASP.Net Class Projects

Usually web service references are added on the main web application but what if you want to isolate it since you'll only be using it on your business layer (class project); the answer, of course, is to add it on your class project. Great, but what if the web service is suddenly relocated to another server? Wouldn't it be nice if you'll have a way to just change the url and point it to the new web service url? To accomplish that, simply follow the following instructions:

1. Set your Class Project Web Reference' URL Behavior property to 'Dynamic'.
2. Open the app.config. The first step will generate an appsettings entry for your web service. Copy the generated appsettings entry.
3. Go to your web application web.config and paste it inside the appSettings and your done.

Share/Save/Bookmark

Sunday, December 28, 2008

How to access web.config from a class project assembly

With VS 2005 it is now easy to access your web.config file from a class within any of your class projects. This is useful for cases wherein your Data Layer needs to access your web.config to retrieve the connectionString section.

public static string GetConnectionStringFromWebConfig()
{
System.Configuration.Configuration cfg =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
//wfp - open web.config located in the root directory
return cfg.ConnectionStrings.ConnectionStrings[0].ConnectionString;

}

of course plain old ConfigurationManager can still be used.


Share/Save/Bookmark

the links

first offering.

this entry will be updated everytime i found new links which i've found useful. the link name pretty much describes what you'll expect so don't whine about 'a short description would be nice' okay (trying to make an excuse for being lazy to provide one)




Share/Save/Bookmark

boot up

without nothing much to do and as sleep continues to evade me tonight, i finally decided to proceed with my new blog which will mostly constitute anything related with my job as a programmer. basically, i'll be posting things that i've encountered that would probably help other kids in their quest for beating the deadlines or just simply co-learning new stuff or laughing at my ignorance.

well it's not much for public consumption but if you did somehow reached my space then you are most welcome to stay and have a look.


Share/Save/Bookmark