Reputation: 13
I'm having difficulty with getting WCF project working with my web application. I've got 3 projects under the solution including asp.net project, DAL, WCF, and WCF tries to use function from DAL, DAL looks up the database connection string from web.config file under asp.net project. However, every time I call database function it returns connection string of null. it seems like I can't access web.config in asp.net project from WCF project. The ideal scenario is to use DAL from both asp.net and WCF without modifying any code.
this DAL library inherit CommonApplication
public abstract class BaseDatabaseApplication : BaseApplication
{
protected readonly string myConnection; // connection string to the publisher (master) database
public BaseDatabaseApplication()
{
// all connection strings are configured here, in the base class
myConnection = CommonApplication.Configuration.ConnectionStrings.ConnectionStrings["myConnection"].ConnectionString;
// some function here
}
}
BaseApplication.cs
public abstract class BaseApplication
{
// since its static, there will only be one instance of it.
private static CommonApplication applications;
public static CommonApplication Applications
{
get { return applications; }
set { applications = value; }
}
}
CommonApplication.cs
public class CommonApplication
{
// only want to process the config once.
private static Configuration configuration;
public static Configuration Configuration
{
get { return configuration; }
set { configuration = value; }
}
}
Upvotes: 0
Views: 616
Reputation: 2821
The System.Configuration.ConfigurationManager class should deals with this situation.
string connectionString = ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;
Try to adapt your application to use it.
Upvotes: 0