简体   繁体   English

Windows Server 2012 R2上的意外崩溃WCF服务

[英]Unexpected crash WCF Service on Windows Server 2012 R2

It will be long post, because I want to explain as mush as possible and detailed my problem. 这将是很长的篇幅,因为我想尽可能多地解释并详细说明我的问题。 I'm new in backend developing and now I'm developing a secured (https) REST web service using WCF, C# and .NET Framework 4.5. 我是后端开发的新手,现在正在开发使用WCF,C#和.NET Framework 4.5的安全(https)REST Web服务。 For this case I use self-signed certificate, configured in IIS. 对于这种情况,我使用在IIS中配置的自签名证书。 My issue is that Service Host seems to crash randomly, without any exception or Message in Trace log. 我的问题是,服务主机似乎随机崩溃,没有任何异常或跟踪日志中的消息。 I tested it in VMware on Windows Server 2012 R2. 我在Windows Server 2012 R2的VMware中对其进行了测试。 On other operating systems (WS 2008, WS 2010) seems to work fine. 在其他操作系统(WS 2008,WS 2010)上似乎可以正常工作。 Here is how I start the service with registering EventHandler for Faulted state: 这是我通过将EventHandler注册为Faulted状态来启动服务的方法:

private ServiceHost listener = null;

public void Start(byte[] certData, string certPassword) {
    int port = Config.MobileServicePort;

    SslCertificate cert = new SslCertificate();

    cert.RemoveCertificate(port);
    cert.InstallCertificate(port, certData, certPassword);

    Uri uri = new Uri(string.Format("https://127.0.0.1:{0}/{1}", port, "MobileService"));

    if (listener != null) {
        listener.Close();
        listener = null;
    }

    listener = new ServiceHost(typeof(MobileService), uri);
    listener.Faulted += FaultedStateHandling;

    try {
        listener.Open();
        Logger.System().Info("REGISTER service at '{0}'", uri.ToString());
    } catch (TimeoutException timeEx) {
        Logger.System().Error("Open timeout exception: " + timeEx);
    } catch (CommunicationException comEx) {
        Logger.System().Error("Open communication exception: " + comEx);
    } catch (Exception ex) {
        Logger.System().Error(ex);
    }
}

Here is Handler for Faulted state: 这是故障状态的处理程序:

private void FaultedStateHandling(object sender, EventArgs e) {
    try {
        Logger.System().Info("<------------***Mobile service Faulted****------------>");
        listener.Abort();
        listener.Faulted -= new EventHandler(FaultedStateHandling);
        int port = Config.MobileServicePort;
        Uri uri = new Uri(string.Format("https://127.0.0.1:{0}/{1}", port, "MobileService"));
        listener = new ServiceHost(typeof(MobileService), uri);
        listener.Faulted += new EventHandler(FaultedStateHandling);
        listener.Open();
        Logger.System().Info("<------------***Mobile service Restarted****------------>");
    } catch (Exception ex) {
        Logger.System().Error(ex);
    }
}

This is my app.config configured for MessageLogging and Tracing: 这是我为MessageLogging和Tracing配置的app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
     <sources>
      <source name="System.ServiceModel"
              switchValue="Critical,Information,ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\log\TraceMessages.svclog" />
        </listeners>
      </source>

       <source name="System.ServiceModel.MessageLogging">
         <listeners>
           <add name="messages"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData="c:\log\MessageLogging.svclog" />
         </listeners>
      </source>

   </sources>
    <trace autoflush="true" />
  </system.diagnostics>

<system.serviceModel>
  <diagnostics>
    <messageLogging
          logEntireMessage="false"
          logMalformedMessages="true"
          logMessagesAtServiceLevel="true"
          logMessagesAtTransportLevel="false"
          maxMessagesToLog="500"
          maxSizeOfMessageToLog="5000"/>
  </diagnostics>
<services>
  <service behaviorConfiguration="MobileBehavior"     name="noq.Mobile.Service.MobileService">
    <endpoint address="" binding="webHttpBinding" 
                         bindingConfiguration="webHttpTransportSecurity" 
                         behaviorConfiguration="REST"
                         contract="noq.Mobile.Service.IMobileService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex"  
              binding="mexHttpsBinding" 
              contract="IMetadataExchange" />
    <!--<host>
      <baseAddresses>
        <add baseAddress="http://localhost:11082/MobileService/" />
      </baseAddresses>
    </host>-->
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webHttpTransportSecurity" maxBufferSize="1000000000"
      maxReceivedMessageSize="1000000000">
      <readerQuotas maxStringContentLength="1000000000" />
      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="REST">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="MobileBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
 </system.serviceModel>
 <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>
</configuration>

I stock with that issue for about 1 month and can't find a solution. 我在此问题上库存了大约1个月,找不到解决方案。 I tried a lot of configurations, and it seems that problem is anywhere deeper. 我尝试了许多配置,似乎问题更深了。 I checked the MSDN forum and support.microsoft. 我检查了MSDN论坛和support.microsoft。 There I found similar issues but not the same, they offer some hot fixes, like that . 在那里,我发现了类似的问题,但不一样的,他们提供了一些热修复程序,就像 Is it possible that issue is associated to VM configuration? 该问题是否可能与VM配置有关? Thanks in advance and for any advice. 在此先感谢您和任何建议。

Finally I've got a solution! 终于我有了解决方案! And I spend too much time to resolve and diagnose such a stupid problem. 而且我花了太多时间来解决和诊断这样一个愚蠢的问题。 Here is how I acted: 这是我的行为方式:

  1. Run -> cmd -> eventvwr 运行-> cmd-> eventvwr
  2. Got a log message with errorcode 0x8009030D from source HttpEvent. 从源HttpEvent获得了一条错误代码为0x8009030D的日志消息。
  3. Applied this solution from msdn blog . msdn blog应用了此解决方案。

    Now the question is: which of this 3 Scenarios fixed my problem? 现在的问题是:这3个场景中的哪一个解决了我的问题? And the second: How to apply this fixes programmatically? 第二:如何以编程方式应用此修复程序? Good Luck! 祝好运! Arty 附庸风雅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Server 2012 R2上Windows Service Platform上的WCFNotSupportedException - WCF on Windows Service PlatformNotSupportedException On Windows Server 2012 R2 WCF 服务适用于 Server 2012 R2,但在 2016 上引发错误 - WCF Service works on Server 2012 R2 but throws error on 2016 Windows Server 2012 r2 中的波斯文化 - Persian culture in Windows Server 2012 r2 从Excel读取Windows Server 2012 R2上的.net Windows服务 - .net Windows service on windows server 2012 R2 read from excel 在 Windows Server 2012 R2 中运行针对 .net framework 1.0 构建的 Windows 服务 - Running Windows service built against .net framework 1.0 in Windows Server 2012 R2 如何使Windows服务从Windows Server 2012 R2中的UI运行 - How to make windows service run from the UI in windows server 2012 R2 在 Windows Server 2012 R2 上构建的应用程序在 Windows Server 2008 R2 上失败 - Application built on Windows Server 2012 R2 fails on windows server 2008 R2 Active Directory中的用户身份验证-Windows Server 2012 R2 - User Authentication in Active Directory - Windows Server 2012 R2 在Windows Server 2012 R2上发送http / 2请求 - send http/2 request on windows server 2012 R2 无法在 Windows 2012 R2 服务器上加载 DLL“tensorflow” - Unable to load DLL 'tensorflow' on Windows 2012 R2 Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM