C# WCF服务无法查看Web.config文件
这是我的第一个WCF服务,这是一个新手问题:在开发环境中运行该服务可以看到Web.config文件 将其部署到服务器上的IIS时,无法看到此文件 访问此文件的类是: 使用系统配置C# WCF服务无法查看Web.config文件,c#,wcf,C#,Wcf,这是我的第一个WCF服务,这是一个新手问题:在开发环境中运行该服务可以看到Web.config文件 将其部署到服务器上的IIS时,无法看到此文件 访问此文件的类是: 使用系统配置 namespace DBService { public static class clsSettings { public static string DBServer {get; set;} public static string DB { get; set; } public stati
namespace DBService
{
public static class clsSettings
{
public static string DBServer {get; set;}
public static string DB { get; set; }
public static string DBUsername { get; set; }
public static string DBPassword { get; set; }
public static Boolean VerboseLogging { get; set; }
public static void LoadSettings()
{
string setting;
try
{
clsSettings.DBUsername = "Login";
clsSettings.DBPassword = "Password";
setting = ConfigurationManager.AppSettings["DatabaseServer"];
if (setting != null) clsSettings.DBServer = setting;
setting = ConfigurationManager.AppSettings["Database"];
if (setting != null) clsSettings.DB = setting;
setting = ConfigurationManager.AppSettings["VerboseLogging"];
if (setting.ToUpper() == "TRUE")
{
clsSettings.VerboseLogging = true;
}
else
{
clsSettings.VerboseLogging = false;
}
}
catch (Exception ex)
{
clsError.LogError("clsSettings", "LoadSettings", ex.Message);
}
}
}
}
而Web.config文件包含:
部署它创建结构:
包含SPService.svc的DBService(文件夹)。它还包含一个包含DBService.dll和DBService.pdb的bin(文件夹) 在上述结构中,bin文件夹位于DBService文件夹中:-) 它还在bin文件夹中创建DBService.dll.config文件。我已将其复制到父文件夹,还将其复制并重命名为Web.config,并将其放置在两个文件夹中。我还尝试将Web.config重命名为Web.config 我已经让程序将设置打印到事件查看器,并且可以看到它们没有被填充 无论我做什么,它仍然不会从配置文件中获取设置。配置文件需要调用什么,应该在哪里?谢谢 您必须使用而不是
ConfigurationManager
用于Windows应用程序的app.config文件,WebConfigurationManager
用于web应用程序及其web.config文件
像这样使用它:
setting = WebConfigurationManager.AppSettings["DatabaseServer"];
谢谢-我已经做了此更改,但它仍然没有加载设置。你能看到要做的任何其他更改吗?不,我创建了一个默认的WCF应用程序,在其中添加了你的应用程序设置,并立即获得了
DatabaseServer
的值。确保IIS服务器上的web.config包含数据吗?也许是你偶然在web.debug.config上写的?@jamespearce:运气好吗?如果你想,我可以把我的测试项目发给你。是的,请:jamespearce111“在”yahoo.co.uk。我想我已经把范围缩小了一点——该服务似乎无法访问web.config文件。我已经检查过它不是只读的,所有用户都可以完全控制它。我还尝试了不同的应用程序池。如果我试图通过服务器上的webbrowser导航到该文件,它会显示“请求过滤模块配置为拒绝URL中包含HiddenSecgment节的路径”。因此,我将在下一步研究该问题。
setting = WebConfigurationManager.AppSettings["DatabaseServer"];