我很難獲得WCF項目與我的Web應用程序一起工作。 我有解決方案下的3個項目,包括asp.net項目,DAL,WCF和WCF嘗試使用DAL中的函數,DAL從asp.net項目下的web.config文件中查找數據庫連接字符串。但是,每次我調用數據庫函數時,都會返回null的連接字符串。似乎我無法從WCF項目訪問asp.net項目中的web.config。理想的情況是在不修改任何代碼的情況下使用來自asp.net和WCF的DAL。WCF與N層架構
這個DAL庫繼承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; }
}
}
你的問題是什麼?你有什麼嘗試? – 2012-08-16 01:48:56
從WCF中,我試圖調用DAL項目中的數據庫函數,DAL項目應該從asp.net項目中的web.config中獲取數據庫連接字符串,但它會返回空值。 WCF - > DAL - > asp.net(web.config) – maxiSK 2012-08-16 02:02:25
您是否嘗試將連接字符串寫入DAL的web.config? – 2012-08-16 02:12:12