使用MsmqIntegrationBinding创建WCF服务时出现异常

使用MsmqIntegrationBinding创建WCF服务时出现异常,wcf,msmqintegrationbinding,Wcf,Msmqintegrationbinding,我的机器是Windows 7 ultimate(64位)。我已经安装了MSMQ,并检查它是否工作正常(运行了MSMQ的一些示例代码) 当我尝试使用MsmqIntegrationBinding类创建WCF服务时,出现以下异常: 打开队列时出错:队列不存在或您没有足够的权限执行此操作。(-1072824317,0xc00e0003)。无法从队列发送或接收消息。请确保MSMQ已安装并正在运行。还要确保队列可以使用所需的访问模式和授权打开。“ 我正在以管理员模式运行visual studio,并通过UR

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

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

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

我正在以管理员模式运行visual studio,并通过URL ACL显式授予自己权限,使用: netsh http add urlacl url=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();
        }
    }
publicstaticvoidmain()
{         
Uri baseAddress=新Uri(@“msmq.formatname:DIRECT=OS:AJITDELL2\private$\Orders”);
使用(ServiceHost ServiceHost=新ServiceHost(typeof(OrderProcessorService),baseAddress))
{
MsmqIntegrationBinding serviceBinding=新的MsmqIntegrationBinding();
serviceBinding.Security.Transport.MsmqAuthenticationMode=MsmqAuthenticationMode.None;
serviceBinding.Security.Transport.MsmqProtectionLevel=System.Net.Security.ProtectionLevel.None;
//serviceBinding.SerializationFormat=MsmqMessageSerializationFormat.Binary;
AddServiceEndpoint(typeof(IOrderProcessor)、serviceBinding、baseAddress);
Open();
//现在可以访问该服务。
WriteLine(“服务准备就绪”);
WriteLine(“服务正在以下帐户中运行:{0}”,WindowsIdentity.GetCurrent().Name);
控制台。WriteLine(“按以终止服务”);
Console.WriteLine();
Console.ReadLine();
//关闭ServiceHostBase以关闭服务。
serviceHost.Close();
}
}

您能帮忙吗?

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

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


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

我在MSMQ>PrivateQueues下手动创建了“订单”队列。同样的例外情况仍然存在:尝试将URI更改为msmq.formatname:DIRECT=OS:。\private$\OrdersId尝试所有组合:msmq.formatname:DIRECT=OS:。\private$\Orders msmq.formatname:DIRECT=OS:localhost\private$\Orders Ajitdel2是我的笔记本电脑名:(最后,问题终于解决了。这是一个安全问题。1.创建了Dan提到的“订单”专用队列。2.右键单击队列并在“安全”选项卡上,为每个用户提供所有权限。然后示例开始工作。Dan,非常感谢提供线索。@Ajit:感谢分享解决方案。