Error 0xc00e0003 in MSMQ + WCF inside a Windows Service

狂风中的少年 提交于 2021-01-28 07:46:28

问题


I am hosting a WCF Service, that uses MSMQ, inside a Windows Service.

Problem:

After installing the service, I am unable to start the service. Event log has following information:

Service cannot be started. System.InvalidOperationException: There was an error opening the queue. Ensure that MSMQ is installed and running, the queue exists and has proper authorization to be read from.

The inner exception may contain additional information. ---> System.ServiceModel.MsmqException: An error occurred while opening the queue:Unrecognized error -1072824317 (0xc00e0003). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization. at System.ServiceModel.Channels.MsmqQueue.OpenQueue() at System.ServiceModel.Channels.MsmqQueue.GetHandle() at System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(String formatName, Int32 accessType, MsmqException& msmqException) --- End of inner exception stack trace --- at System.ServiceModel.Channels.MsmqVerifier.VerifyReceiver(MsmqReceiveParameters receiveParameters, Uri listenUri) at System.ServiceModel.Channels.MsmqTransport...

Note:

  1. The windows service can create the queue, but cannot open it for read/write.
  2. The windows service is running under LocalSystem privilege.
  3. SYSTEM has full access permissions on the queue.

Research

  1. According to MSDN it says:

MQ_ERROR_QUEUE_NOT_FOUND (0xC00E0003)

Returned when Message Queuing cannot find the queue. Such queues include public queues not registered in the directory service and Internet queues that do not exist in the MSMQ namespace. This error is also returned when the user does not have sufficient permissions to perform the operation.

This is impossible, as the queue DOES exist (its creating it in the previous line of code) and has all the permissions.

  1. Visited all sites in first page of Google. Tried all, and the same exception.

My App.Config file

<?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>

回答1:


Well I found a solution to the problem.

The problem was the word "localhost" which does not work properly with Active Directory system. So you have to explicitly state your machine name.

<?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>


来源:https://stackoverflow.com/questions/25887810/error-0xc00e0003-in-msmq-wcf-inside-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!