gpt4 book ai didi

c# - 偶发性 WCF 服务激活错误并显示消息 - 访问 IIS 元数据库时出错

转载 作者:太空狗 更新时间:2023-10-29 20:39:27 26 4
gpt4 key购买 nike

我正在开发一个项目,之前我只托管了一个 WCF 服务。过去一切正常。后来,作为增强功能的一部分,我们向同一个项目添加了两个具有不同接口(interface)和不同 SVC 文件的 WCF 服务。所有三个服务共享相同的 web.config,它定义了三个端点(对应于每个服务)。

我的项目的 WCF 服务作为单独的网站托管,具有自己的应用程序池和端口号。我的所有三个服务共享同一个应用程序池。

使用此设置,当我多次将应用程序部署到测试服务器时,我会遇到如下偶发错误并且服务停止工作。在这三个服务中,一次有一个或两个出现此错误,其他服务继续工作。

    System.ServiceModel.ServiceHostingEnvironment+HostingManager/4032828
System.ServiceModel.ServiceActivationException: The service '...svc' cannot be activated due to an exception during compilation. The exception message is: An error occurred while accessing the IIS Metabase.. --->

System.Runtime.InteropServices.COMException: An error occurred while accessing the IIS Metabase.
at System.ServiceModel.Activation.MetabaseReader..ctor

我为 web 服务启用了 svclogs,我看到了类似的东西

......
AppDomain unloading
To: construct ServiceHost 'myservice1'
From: construct ServiceHost 'myservice1'
To: Open ServiceHost 'myservice1'
From: ServiceHost 'myservice1'
ASP.NET hosted service activated
**Wrote To Eventlog** << Exception at this point for myservice2.

我试过了This options但它没有帮助。我也在网上搜索过,但没有找到任何其他可以提供帮助的解决方案。

我在测试服务器上安装了 IIS6。

如有任何帮助,我们将不胜感激。

更新:


我观察到一个规律。空闲时间过后,首先被命中的服务被正确激活,其他服务失败。此外,要添加到端口部分,我们特别提到将运行此服务的端口。对于我的应用程序来说,端口号是 25000,那么此服务器上没有其他应用程序共享此端口号,只有我的应用程序。因此,如果有多个服务,那么它们将共享端口,但对于具有多个 SVC 服务的其他项目,同样存在相同的设置,并且没有人遇到过这个问题(据我所知)。

更新 2:下面是配置文件。我输入了配置文件,但已尽量保持准确。 (请忽略区分大小写的东西)

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="prod.xxx.net" />
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>

<behaviours>
<serviceBehaviours>
<behaviour name="firstServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication mapClientCertificateToWindowsAccount="true" />
</clientCertificate>
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behaviour>

<behaviours>
<serviceBehaviours>
<behaviour name="secondServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication mapClientCertificateToWindowsAccount="true" />
</clientCertificate>
</serviceCredentials>
</behaviour>

<behaviours>
<serviceBehaviours>
<behaviour name="thirdServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication mapClientCertificateToWindowsAccount="true" />
</clientCertificate>
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behaviour>

<services>
<service behaviourConfiguration="firstServiceBehaviour" name="...">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="firstServiceEndPoint" contract="IfirstServiceContract" />
</service>

<service behaviourConfiguration="secondServiceBehaviour" name="...">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="secondServiceEndPoint" contract="IsecondServiceContract" />
</service>

<service behaviourConfiguration="thirdServiceBehaviour" name="...">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding"
name="thirdServiceEndPoint" contract="IthirdServiceContract" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</System.ServiceModel>

最佳答案

我不会说这是完整的答案,但这在一定程度上帮助解决了我们的问题。我仍然想知道问题实际原因的原因/解决方案。我提到这项变通办法是因为这可能会帮助那些可能面临类似问题的人暂时解决他们的问题。

正如我提到的,只有在应用程序空闲一段时间后才会出现问题。在那种情况下,IIS 正在关闭(卸载)应用程序的 AppDomain(这来自 SVC 日志)。

因此,我们创建了一个简单的控制台应用程序,它每 5-10 分钟访问我们应用程序的所有服务,并且不会让 AppDomain 关闭。有另一种方法可以实现此目的 - 将 IIS 配置设置为不卸载 AppDomain(这对我们来说不太可行,提供了共享基础结构)。这帮助我们完成了测试。

然后,当我们转移到负载平衡环境(接近生产的测试环境)时,我们突然停止了这个问题,并且通过一些分析我们发现负载平衡器本身正在对这些服务执行 ping 操作,以确保它们是正确的起来,因为这些服务的应用程序域从未被卸载。

因此,目前我们可以说我们在负载平衡环境中没有遇到此问题,但问题仍然是为什么它甚至会发生(对于非负载平衡环境)。

关于c# - 偶发性 WCF 服务激活错误并显示消息 - 访问 IIS 元数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20914214/

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