带有消息的偶发WCF服务激活错误 - 访问IIS元数据库时发生错误

Gua*_*nxi 7 c# asp.net iis wcf web-services

我正在讨论一个项目,早些时候我只托管单个WCF服务.一切都习以为常.稍后,作为增强功能的一部分,我们将两个WCF服务添加到具有不同接口和不同SVC文件的同一项目中.所有三个服务共享相同的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
Run Code Online (Sandbox Code Playgroud)

我为webservice启用了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.
Run Code Online (Sandbox Code Playgroud)

我试过这个选项,但它没有帮助.我也在网上搜索,但没有找到任何其他可以提供帮助的解决方案.

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

任何帮助将不胜感激.

更新:


我观察到了一种模式.空闲时间之后,无论哪个服务首先被正确激活,其他服务都会失败.另外,要添加到Port部分,我们特别提到将运行此服务的端口.对于我的应用程序说端口号是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>
Run Code Online (Sandbox Code Playgroud)

Gua*_*nxi 1

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

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

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

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

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