我的机器是 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();
}
}
你能帮忙吗?