Win Service getting permission denied to Message Queuing

Bob The Janitor picture Bob The Janitor · Sep 17, 2010 · Viewed 17.9k times · Source

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>

Answer

Bob The Janitor picture Bob The Janitor · Sep 17, 2010

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