2

我的机器是 Windows 7 终极版(64 位)。我已经安装了 MSMQ 并检查了它是否工作正常(为 MSMQ 运行了一些示例代码)。

当我尝试使用 MsmqIntegrationBinding 类创建 WCF 服务时,出现以下异常:

“打开队列时出错:队列不存在或您没有足够的权限执行该操作。(-1072824317, 0xc00e0003)。无法从队列发送或接收消息。请确保已安装 MSMQ 并运行。还要确保队列可以使用所需的访问模式和授权打开。

我在管理员模式下运行 Visual Studio,并使用以下 URL ACL 明确授予自己权限:netsh http add urlacl url= http://+:80/ user=DOMAIN\user

下面是代码:

 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();
        }
    }

你能帮忙吗?

4

1 回答 1

3

确保您已在 MSMQ 中创建“订单”队列。

在 Windows Server 2008 中,您可以从服务器管理器中执行此操作(右键单击我的电脑并选择管理),然后选择功能 -> 消息队列 -> 专用队列。右键单击私人队列并在那里添加您的“订单”队列。

您可能还想查看 Nicholas Allen 的文章:诊断常见队列错误。它表明您的错误只能是:“队列不存在,或者您可能错误地指定了队列名称”。所有其他错误情况都会引发不同的异常。

于 2009-12-23T12:02:32.193 回答