Windows 服务中 MSMQ + WCF 中的错误 0xc00e0003 [英] Error 0xc00e0003 in MSMQ + WCF inside a Windows Service

查看:71
本文介绍了Windows 服务中 MSMQ + WCF 中的错误 0xc00e0003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 服务中托管使用​​ MSMQ 的 WCF 服务.

问题:

安装服务后,我无法启动服务.事件日志有以下信息:

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

<块引用>

内部异常可能包含附加信息.--->System.ServiceModel.MsmqException: 打开队列:无法识别的错误 -1072824317 (0xc00e0003).消息不能从队列中发送或接收.确保安装了 MSMQ 并且跑步.还要确保队列可用所需的访问模式和授权.在System.ServiceModel.Channels.MsmqQueue.OpenQueue() 在System.ServiceModel.Channels.MsmqQueue.GetHandle() 在System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(String格式名称、Int32 访问类型、MsmqException&msmqException) --- 结束内部异常堆栈跟踪 --- 在System.ServiceModel.Channels.MsmqVerifier.VerifyReceiver(MsmqReceiveParametersreceiveParameters, Uri listenUri) atSystem.ServiceModel.Channels.MsmqTransport...

注意:

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

研究

  1. 根据 MSDN 它说:

<块引用>

MQ_ERROR_QUEUE_NOT_FOUND (0xC00E0003)

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

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

  1. 访问了 Google 第一页中的所有网站.都试过了,还是一样的例外.

我的 App.Config 文件

<配置><configSections><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/></configSections><!-- Log4net 日志记录设置--><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"/></布局><filter type="log4net.Filter.LevelRangeFilter"><levelMin value="INFO"/><levelMax value="致命"/></过滤器></appender><根><level value="DEBUG"/><appender-ref ref="RollingFileAppender"/></root><应用设置><add key="QueueName" value=".\private$\ftpuploader"/></appSettings><system.serviceModel><diagnostics performanceCounters="All"/><服务><服务名称="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"/><主机><基地址><add baseAddress="net.msmq://localhost/private"/><add baseAddress="http://localhost:9271"/><!-- 哈代-拉马努金数,颠倒了!--></baseAddresses></host></服务></服务><绑定><netMsmqBinding><binding name="msmqFileUploader" exactOnce="false"><安全模式=无"/></binding></netMsmqBinding></绑定><行为><服务行为><行为名称=msmqBehavior"><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="true"/></行为></serviceBehaviors></行为></system.serviceModel><启动><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

解决方案

好吧,我找到了解决问题的方法.

问题是localhost"这个词在 Active Directory 系统中不能正常工作.所以你必须明确说明你的机器名称.

<配置><configSections><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/></configSections><!-- Log4net 日志记录设置--><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"/></布局><filter type="log4net.Filter.LevelRangeFilter"><levelMin value="INFO"/><levelMax value="致命"/></过滤器></appender><根><level value="DEBUG"/><appender-ref ref="RollingFileAppender"/></root><应用设置><add key="QueueName" value=".\private$\ftpuploader"/></appSettings><system.serviceModel><diagnostics performanceCounters="All"/><服务><服务名称="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"/><主机><基地址><add baseAddress="net.msmq://MachineName/private"/><!-- MachineName 而不是 localhost --><add baseAddress="http://MachineName:9271"/><!-- Hardy-Ramanujan 的数字,颠倒了!--><!-- MachineName 而不是 localhost --></baseAddresses></host></服务></服务><绑定><netMsmqBinding><binding name="msmqFileUploader" exactOnce="false"><安全模式=无"/></binding></netMsmqBinding></绑定><行为><服务行为><行为名称=msmqBehavior"><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="true"/></行为></serviceBehaviors></行为></system.serviceModel><启动><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

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>

解决方案

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>

这篇关于Windows 服务中 MSMQ + WCF 中的错误 0xc00e0003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆