Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

c# 4.0 - Win Service getting permission denied to Message Queuing

I have a WinService that can't start because NServiceBus throws "Service cannot be started. System.Messaging.MessageQueueException (0x80004005): Access to Message Queuing system is denied."

This is on Windows 7

I have tried to run the service as: LocalSystem, Localservice, and NetworkService

here is how I'm setting up NServiceBus

 private static IBus _serviceBus;
    private static AuditMessageHandler _messageHandler;

    public AuditQueueProcessor()
    {
        _messageHandler = new AuditMessageHandler();
        _serviceBus = Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .IsTransactional(true)
            .PurgeOnStartup(false)
            .UnicastBus()
            .ImpersonateSender(false)
            .LoadMessageHandlers()
            .CreateBus()
            .Start();
    }

here is my Config

<configuration>
  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>

  </configSections>

  <MsmqTransportConfig InputQueue="LoggerInputQueue" ErrorQueue="LoggerInputError" NumberOfWorkerThreads="1" MaxRetries="5"/>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="Truckstop2.Imports.Objects.AuditMessage,Truckstop2.Imports.Objects" Endpoint="InputQueue@newimp001" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the solution !

It's because service incorporated in NETWORK SERVICE user. You need to set permisions to the private MSMQ your accessing to do this

  1. open Computer Management
  2. Expand Message Queuing
  3. Expand Private Queues
  4. right click on the Queue your using and select Properties
  5. select the security tab and set permissions to your local user

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...