views:

267

answers:

1

My machine is Windows 7 ultimate (64 bit). I have installed MSMQ and checked that it is working fine (ran some sample codes for MSMQ).

When i try to create a WCF Service using MsmqIntegrationBinding class, i get the below exception:

"An error occurred while opening the queue:The queue does not exist or you do not have sufficient permissions to perform the operation. (-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."

I am running the visual studio in Administrator mode and explicitly grant permission to myself via a URL ACL using: netsh http add urlacl url=http://+:80/ user=DOMAIN\user

Below is the code:

 public static void Main()
    {         
        Uri baseAddress = new Uri(@"msmq.formatname:DIRECT=OS:AJITDELL2\private$\Orders");
        using (ServiceHost serviceHost = new ServiceHost(typeof(OrderProcessorService), baseAddress))

        {

            MsmqIntegrationBinding serviceBinding = new MsmqIntegrationBinding();
            serviceBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            serviceBinding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None;
            //serviceBinding.SerializationFormat = MsmqMessageSerializationFormat.Binary;
            serviceHost.AddServiceEndpoint(typeof(IOrderProcessor), serviceBinding, baseAddress);
            serviceHost.Open();

            // The service can now be accessed.
            Console.WriteLine("The service is ready.");
            Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name);
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            serviceHost.Close();
        }
    }

Can you please help?

+1  A: 

Make sure you have created the "Orders" queue in MSMQ.

In Windows Server 2008, you can do so from the Server Manager (right click on My Computer and select Manage), then Features -> Message Queuing -> Private Queues. Right click on Private Queues and add your "Orders" queue there.

You may also want to check Nicholas Allen's article: Diagnosing Common Queue Errors. It suggests that your error can only be: "that the queue does not exist, or perhaps you've specified the queue name incorrectly". All the other error cases would have thrown a different exception.

Daniel Vassallo
I manually created the "Orders" queue under MSMQ>PrivateQueues. Still the same exception is thrown
Ajit Singh
Ajit: Try changing the URI to msmq.formatname:DIRECT=OS:.\private$\Orders
Daniel Vassallo
Did try all the combinations:msmq.formatname:DIRECT=OS:.\private$\Ordersmsmq.formatname:DIRECT=OS:localhost\private$\Ordersmsmq.formatname:DIRECT=OS:AJITDELL2\private$\OrdersAJITDELL2 is my laptop name. :(
Ajit Singh
Finally, at last, the problem got resolved. It was a security issue. 1. Created "Orders" private queue as mentioned by Dan.2. Right click the queue and on "Security" tab, provided all the permissions to Everyone user.Then the example is working. Dan, Thanks a lot for providing the clue.
Ajit Singh
@Ajit: Thanks for sharing the solution.
Daniel Vassallo