从Microsoft Messaging Queue读取时出现问题 [英] Problems reading from Microsoft Messaging Queues

查看:54
本文介绍了从Microsoft Messaging Queue读取时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从MSMQ上阅读时遇到问题.当我写入队列时,它可以正常工作,但是当我尝试从队列中读取该消息时,出现以下异常:队列不存在,或者您没有足够的权限执行该操作."队列确实存在,并且我对计算机和队列拥有完全权限.这是我的代码:

公用字符串路径= @.\ private $ \";

I have problems reading from my MSMQ. When I write to the queue, it works perfectly, but when I try to read that message from the queue, I get the following exception: "The queue does not exist or you do not have sufficient permissions to perform the operation." The queue does exists, and I have full permissions on the machine and queue. Here is my code:

public string path = @".\private$\";

public void WriteToQueue(string QueueName, object messageObject)
     {
        try
        {
            path = path +  QueueName;
            MessageQueue msmq = null;

            if (!MessageQueue.Exists(path))
            {
                msmq = MessageQueue.Create(path);
            }
            else
            {
                msmq = new MessageQueue(path);
                    
            }
             msmq.Formatter = new XmlMessageFormatter(new Type[] { typeof(string)});
             msmq.Send(messageObject);
             msmq.Close();
            }
            catch (MessageQueueException ex)
            {
                System.ArgumentException argEx = neArgumentException(ex.ToString());
                throw argEx;
            }
           
            path = @".\private$\";
        }





public string ReadQueue(string QueueName)
     {
         try
         {
             path = path + QueueName;

             MessageQueue msmq = new MessageQueue(path);

             string msg;
             msmq.Formatter = new XmlMessageFormatter(new Type[] { typeof(string)});

             msg = msmq.Receive().Body.ToString();  //exception is thrown here
             path = @".\private$\";

             return msg;
            }
         catch (Exception ex)
         {
             return null;
         }
        }

推荐答案

\;

\";

public void WriteToQueue(string QueueName, object messageObject)
     {
        try
        {
            path = path +  QueueName;
            MessageQueue msmq = null;

            if (!MessageQueue.Exists(path))
            {
                msmq = MessageQueue.Create(path);
            }
            else
            {
                msmq = new MessageQueue(path);
                    
            }
             msmq.Formatter = new XmlMessageFormatter(new Type[] { typeof(string)});
             msmq.Send(messageObject);
             msmq.Close();
            }
            catch (MessageQueueException ex)
            {
                System.ArgumentException argEx = neArgumentException(ex.ToString());
                throw argEx;
            }
           
            path = @".\private


\" ; }
\"; }





public string ReadQueue(string QueueName)
     {
         try
         {
             path = path + QueueName;

             MessageQueue msmq = new MessageQueue(path);

             string msg;
             msmq.Formatter = new XmlMessageFormatter(new Type[] { typeof(string)});

             msg = msmq.Receive().Body.ToString();  //exception is thrown here
             path = @".\private


\" ; 返回味精; } 捕获(例外) { 返回 ; } }
\"; return msg; } catch (Exception ex) { return null; } }


这篇关于从Microsoft Messaging Queue读取时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆