WCF 服务在一段时间后自行消亡

标签 wcf hosting

我面临一个与托管 WCF 服务(.NET Framework 4、IIS 7、Windows 2008 Standard SP2)相关的特殊问题。

在我部署该服务后,它可以正常工作一段时间,并且通过抛出文件未找到异常而自行消亡。异常详情如下。

该应用程序托管在 IIS7 中,具有指向 .NET Framework 4 版本的特定应用程序池。我已经使用 FusionLog 在丢失的程序集上找到了更多信息,但没有运气。但是,如果我从托管服务器中删除所有程序集并从构建文件夹中再次复制它,它会再次开始工作,绝对没有问题。我无法解释这种行为并搜索/尝试了很多以找到答案。为了提供更多信息,该服务是一个本地程序集,我使用企业库进行异常处理和日志记录。 WCF Service 我们使用 httpBinding。程序集是调试版本。请帮忙。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    ------    
  <!-- Begin .......Exception Handling Configuration-->
  <!-- End .........Exception Handling configuration-->

  <!-- Start .............Logging Configuration-->
  <!--End............ Logging Configuration-->

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
        <identity impersonate="true" />
  </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <defaultDocument>
            <files>
                <add value="Service.svc" />
            </files>
        </defaultDocument>
    </system.webServer>

    <!-- Start WCF ................Settings-->
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" />
      <endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
    </diagnostics>
    <!-- Begin..Included for Switching off Security-->
    <bindings>
      <basicHttpBinding>
        <binding name="httpBindingConfig" closeTimeout="24.01:00:00" openTimeout="24.01:00:00" receiveTimeout="24.10:00:00" sendTimeout="24.01:00:00" />
      </basicHttpBinding>
    </bindings>
    <!-- End ..Included for Switching off Security-->
    <services>
      <service name="Service">
        <endpoint binding="mexTcpBinding" bindingConfiguration="" name="EndPointMex" contract="ICommunicatorService" />
        <endpoint address="http://<>/Service.svc" binding="basicHttpBinding" bindingConfiguration="" name="EndPointHttp" contract="Reflections.IService" />
        <host>
          <timeouts closeTimeout="24.00:10:00" openTimeout="24.01:00:00" />
        </host>
      </service>
    </services>
    <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true" />
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <!-- End WCF ................Settings-->  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
 </configuration>

事件记录日志 - - - - - - - - - - -
 Log Name:      Application
    Source:        System.ServiceModel 4.0.0.0
    Date:          7/5/2011 10:39:47 AM
    Event ID:      3
    Task Category: WebHost
    Level:         Error
    Keywords:      Classic
    User:          NETWORK SERVICE
    Computer:      <Masked for Security Reasons>
    Description:
    WebHost failed to process a request.
     Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/12036987
     Exception: System.ServiceModel.ServiceActivationException: The service '/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.Load(String assemblyString)
       at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       --- End of inner exception stack trace ---
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
     Process Name: w3wp
     Process ID: 3480

ASP.NET 页面中显示的错误-----------------
Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' could not be loaded.


Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
 (Fully-specified)
LOG: Appbase = file://path/
LOG: Initial PrivatePath = \\path\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: \\path\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
LOG: The same bind was seen before, and was failed with hr = 0x80070002.



Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +210
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1440
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +687598
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +301390
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +8898292
-------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

融合日志中的错误
*** Assembly Binder Log Entry  (7/22/2011 @ 10:34:51 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
 (Fully-specified)
LOG: Appbase = file://path/
LOG: Initial PrivatePath = \\path\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b44c783a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b44c783a
LOG: AppName = 34485861
Calling assembly : (Unknown).
===
LOG: Start binding of native image Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e.
WRN: No matching native image found.

这里讨论了一个类似的问题,但找不到答案 Changing the web.config takes the WCF service down?

最佳答案

未找到的文件是否可能是一个红鲱鱼,而您只是遇到不事件超时?我记得当我编写我的第一个 WCF 服务时,我没有意识到超时设置默认为很短的时间,比如几分钟。我认为您可以将它们设置为很长(例如 24 天)。

在我的 部分之后的 部分中的我的应用程序配置中,我有:

    <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="tcp_unsecured" receiveTimeout="infinite" sendTimeout="00:00:30">
                <security mode="None">
                </security>
            </binding>
        </netTcpBinding>
    </bindings>

接下来是我的服务和行为部分。这是我右键单击并在 app.config 上选择“编辑 WCF 配置”时对话框的 png。我在 app.config xml 文件中输入了“infinite”,但对话框将其转换为相关的大值。
enter image description here

更新:在我的中介类中,这里是设置 NetTcpBinding 的构造函数。我包含这个是因为我似乎需要在代码中设置超时。
    public DspServiceMediator( String serviceAddress)
    {
        EndpointAddress end_point = new EndpointAddress(serviceAddress);
        NetTcpBinding new_tcp = new NetTcpBinding(SecurityMode.None)
                                {ReceiveTimeout = TimeSpan.MaxValue,
                                 SendTimeout = new TimeSpan(0, 0, 30)
                                };

        _dspClient = new DspServiceClient(new_tcp, end_point);
    }

关于WCF 服务在一段时间后自行消亡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578368/

相关文章:

c# - SSL/TLS WCF 问题

amazon-s3 - 亚马逊S3 : Static Web Sites: Custom Domain or Subdomain

asp.net-mvc - asp.net 核心应用程序。 500内部服务器错误

python - 如何在线运行python脚本?

hosting - 使用 "developers background"运行我自己的服务器?

wcf - .Net Core 不支持 WSHttpBinding

C# SOAP-Service 方法参数上缺少命名空间

c# - 什么可能是我的 C# WCF 服务上的速率限制 CPU 周期?

jquery - 格式化 Jquery AJAX post 以将数据发送到 WCF 服务

ruby-on-rails-3 - 托管 5 个 Ruby on Rails 3 应用程序需要多少 CPU/RAM?