【问题标题】:Exception in creating a WCF Service using MsmqIntegrationBinding使用 MsmqIntegrationBinding 创建 WCF 服务时出现异常
【发布时间】:2009-12-23 11:57:53
【问题描述】:

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

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

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

我正在管理员模式下运行 Visual Studio,并通过 URL ACL 使用以下命令明确授予自己权限: netsh http 添加 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();
        }
    }

你能帮忙吗?

【问题讨论】:

    标签: wcf msmqintegrationbinding


    【解决方案1】:

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

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

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

    【讨论】:

    • 我在 MSMQ>PrivateQueues 下手动创建了“Orders”队列。仍然抛出相同的异常
    • Ajit:尝试将 URI 更改为 msmq.formatname:DIRECT=OS:.\private$\Orders
    • 尝试了所有组合:msmq.formatname:DIRECT=OS:.\private$\Orders msmq.formatname:DIRECT=OS:localhost\private$\Orders msmq.formatname:DIRECT=OS: AJITDELL2\private$\Orders AJITDELL2 是我的笔记本电脑名称。 :(
    • 终于,问题终于解决了。这是一个安全问题。 1. 创建了 Dan 提到的“订单”私人队列。 2. 右键单击​​队列并在“安全”选项卡上,为所有人用户提供所有权限。然后这个例子就起作用了。丹,非常感谢您提供线索。
    • @Ajit:感谢分享解决方案。
    猜你喜欢
    • 1970-01-01
    • 2010-12-11
    • 2019-04-19
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    相关资源
    最近更新 更多