gpt4 book ai didi

asp.net - 经过一段时间的工作后,IIS/ASP.Net 无法从 WCF Web 服务的 web.config 文件中读取设置

转载 作者:行者123 更新时间:2023-12-02 13:43:31 24 4
gpt4 key购买 nike

我们有一个在 IIS7 上运行的 ASP.Net Web 应用程序,与 WCF Web 服务进行通信,该服务处理从此 Web 应用程序到达的请求。

工作一段时间后(可能是一周或几天),WCF Web 服务开始无法读取其 web.config 文件中的设置,并记录了以下异常:

System.NullReferenceException

ABC.Communication.DataContract.RefreshRequest System.NullReferenceException: Object reference not set to an instance of an object.
at System.Xml.XmlNode.RemoveChild(XmlNode oldChild)
at System.Xml.XmlNode.RemoveAll()
at System.Xml.XmlElement.set_InnerXml(String value)
at System.Configuration.LocalFileSettingsProvider.XmlEscaper.Unescape(String escapedString)
at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at ABC.Communication.DataContract.Request.ValidateIpAddress() in C:\Project\ABC.Server\ABC.Communication\DataContract\Request.Validation.cs:line 955
at ABC.Communication.DataContract.RefreshRequestBase.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequestBase.cs:line 46
at ABC.Communication.DataContract.RefreshRequest.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequest.cs:line 30
at ABC.Communication.ClientCommunicationService.HandleRequest(Request request) in C:\Project\ABC.Server\ABC.Communication\ClientCommunicationService.cs:line 116

System.ArgumentException

ABC.Communication.DataContract.RefreshRequest System.ArgumentException: The node to be removed is not a child of this node.
at System.Xml.XmlNode.RemoveChild(XmlNode oldChild)
at System.Xml.XmlNode.RemoveAll()
at System.Xml.XmlElement.set_InnerXml(String value)
at System.Configuration.LocalFileSettingsProvider.XmlEscaper.Unescape(String escapedString)
at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at ABC.Communication.DataContract.Request.ValidateIpAddress() in C:\Project\ABC.Server\ABC.Communication\DataContract\Request.Validation.cs:line 955
at ABC.Communication.DataContract.RefreshRequestBase.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequestBase.cs:line 46
at ABC.Communication.DataContract.DataContracts.RefreshRequest.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequest.cs:line 30
at ABC.Communication.ClientCommunicationService.HandleRequest(Request request) in C:\Project\ABC.Server\ABC.Communication\ClientCommunicationService.cs:line 116

System.Configuration.SettingsPropertyNotFoundException:

ABC.Communication.DataContract.RefreshRequest System.Configuration.SettingsPropertyNotFoundException: The settings property 'ValidateIpConnections' was not found.
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at ABC.Communication.DataContract.Request.ValidateIpAddress() in C:\Project\ABC.Server\ABC.Communication\DataContract\Request.Validation.cs:line 955
at ABC.Communication.DataContract.RefreshRequestBase.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequestBase.cs:line 46
at ABC.Communication.DataContract.RefreshRequest.Validate() in C:\Project\ABC.Server\ABC.Communication\DataContract\RefreshRequest.cs:line 30
at ABC.Communication.ClientCommunicationService.HandleRequest(Request request) in C:\Project\ABC.Server\ABC.Communication\ClientCommunicationService.cs:line 116

引发此异常的代码非常简单:

private void ValidateIpAddress() {
// Load custom settings
CustomSettings settings = GetCustomSettings();

if (!settings.ValidateIpConnections) // here the exception is thrown!
return;

// the rest of code never reached...
}

对自定义设置实例的访问现在在顶级父类Request中实现,如下所示:

public abstract partial class Request
{
/// <summary>
/// Custom settings.
/// </summary>
private static readonly CustomSettings customSettings;

/// <summary>
/// .cctor().
/// </summary>
static Request()
{
customSettings = new CustomSettings();
}

/// <summary>
/// Get custom settings.
/// </summary>
/// <returns>Custom settings.</returns>
internal static CustomSettings GetCustomSettings()
{
return customSettings;
}

// ....
}
<小时/>

不仅此特定设置 ValidateIpConnections 会出现此问题,WCF 服务的 web.config 文件中的其他设置也会出现此问题。

目前还不清楚这个问题的原因是什么,它不能持续稳定地重现。它似乎并不直接取决于负载/用户数量/打开的 session 。有时,该网站可以顺利运行数周,然后该问题每周出现一次,然后连续出现几天。可能与应用池中某些worker进程的回收有关。

我们以前在 Windows Server 2003 (IIS 6.0) 上遇到它,现在在带有 IIS 7.0 的 Windows Server 2008 上遇到它,因此它似乎与 IIS 版本没有直接关系。

我怀疑通过 Request 的只读静态成员为所有仅初始化一次的子类共享对 CustomSettings 类实例的访问可能存在问题。

任何帮助/建议将不胜感激。

最佳答案

我认为您可以避免使用自定义设置类,因为 web.config 在第一次访问时会被缓存。参见

ASP.NET: Where/how is web.config cached?

因此无需自己进行缓存,然后就可以排除这种情况。

我们的一台生产服务器上也遇到了类似的问题,结果发现病毒扫描程序正在扫描 web.config 文件,从而导致应用程序池回收。

我会推荐

关于asp.net - 经过一段时间的工作后,IIS/ASP.Net 无法从 WCF Web 服务的 web.config 文件中读取设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com