Windows服务内的MSMQ+WCF中出现错误0xc00e003

本文关键字:错误 0xc00e003 MSMQ+WCF 服务 Windows | 更新日期: 2023-09-27 18:22:14

我正在Windows服务中托管一个使用MSMQ的WCF服务。

问题:

安装该服务后,我无法启动该服务。事件日志包含以下信息:

无法启动服务。System.InvalidOperationException:打开队列时出错。请确保MSMQ已安装并正在运行,队列存在并且具有适当的读取权限。

内部异常可能包含其他信息。--->System.ServiceModel.MsmqException:打开队列:无法识别的错误-1072824317(0xc00e003)。消息不能从队列发送或接收。确保MSMQ已安装,并且跑步还要确保队列可用以打开所需的访问模式和授权。在位于的System.ServiceModel.Channels.MsmqQueue.OpenQueue()位于的System.ServiceModel.Channels.MsmqQueue.GetHandle()System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(字符串formatName,Int32 accessType,MsmqException&msmqException)---结束内部异常堆栈跟踪--位于System.ServiceModel.Channels.MsmqVerifier.VerifyReceiver(MsmqReceiveParametersreceiveParameters,Uri listenUri)System.ServiceModel.Channels.MsmqTransport…

注意:

  1. windows服务可以创建队列,但不能打开它进行读/写
  2. windows服务在LocalSystem权限下运行
  3. SYSTEM对队列具有完全访问权限

研究

  1. 据MSDN报道:

MQ_ERROR_QUEUE_NOT_FOUND(0xC00E0003)

当消息队列找不到队列时返回。这样的队列包括未在目录服务中注册的公共队列,以及MSMQ命名空间中不存在的Internet队列。此错误是当用户没有足够的权限执行操作。

这是不可能的,因为队列确实存在(它在前一行代码中创建它)并且具有所有权限。

  1. 访问了谷歌首页中的所有网站。尝试了所有,但出现了相同的异常

我的应用程序配置文件

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
  </configSections>
  <!-- Log4net Logging Setup -->
  <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <file value="D:''FTPFileUpload.txt"/>
      <appendToFile value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="0"/>
      <maximumFileSize value="10MB"/>
      <staticLogFileName value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO"/>
        <levelMax value="FATAL"/>
      </filter>
    </appender>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="RollingFileAppender"/>
    </root>
  </log4net>
  <appSettings>
    <add key="QueueName" value=".'private$'ftpuploader"/>
  </appSettings>
  <system.serviceModel>
    <diagnostics performanceCounters="All"/>
    <services>
      <service name="FTPUploader.Core.FtpUpload" behaviorConfiguration="msmqBehavior">
        <endpoint name="msmq" address="MsmqWcfFtpUpload" binding="netMsmqBinding" bindingConfiguration="msmqFileUploader" contract="FTPUploader.Contracts.IFtpUpload"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.msmq://localhost/private"/>
            <add baseAddress="http://localhost:9271"/> <!-- Hardy-Ramanujan's Number, Reversed!-->
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netMsmqBinding>
        <binding name="msmqFileUploader" exactlyOnce="false">
          <security mode="None"/>
        </binding>
      </netMsmqBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="msmqBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Windows服务内的MSMQ+WCF中出现错误0xc00e003

我找到了这个问题的解决方案。

问题出在单词"localhost"上,它不能与Active Directory系统正常工作。因此,您必须明确说明您的机器名称。

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
  </configSections>
  <!-- Log4net Logging Setup -->
  <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <file value="D:''FTPFileUpload.txt"/>
      <appendToFile value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="0"/>
      <maximumFileSize value="10MB"/>
      <staticLogFileName value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO"/>
        <levelMax value="FATAL"/>
      </filter>
    </appender>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="RollingFileAppender"/>
    </root>
  </log4net>
  <appSettings>
    <add key="QueueName" value=".'private$'ftpuploader"/>
  </appSettings>
  <system.serviceModel>
    <diagnostics performanceCounters="All"/>
    <services>
      <service name="FTPUploader.Core.FtpUpload" behaviorConfiguration="msmqBehavior">
        <endpoint name="msmq" address="MsmqWcfFtpUpload" binding="netMsmqBinding" bindingConfiguration="msmqFileUploader" contract="FTPUploader.Contracts.IFtpUpload"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.msmq://MachineName/private"/> <!-- MachineName instead of localhost -->
            <add baseAddress="http://MachineName:9271"/> <!-- Hardy-Ramanujan's Number, Reversed!--> <!-- MachineName instead of localhost -->
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netMsmqBinding>
        <binding name="msmqFileUploader" exactlyOnce="false">
          <security mode="None"/>
        </binding>
      </netMsmqBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="msmqBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>