我有一个案例将信息从一种形式转换为另一种形式,而且耗时。我写了一个Windows服务来完成所有的转换。此Windows服务侦听MSMQ,其中将从ASP.NET应用程序写入请求消息。
当用户触发ASP.NET页面上的按钮单击时,转换踢开始。单击按钮,我写入Windows服务侦听的MSMQ。完成转换后,它会将响应写回responseMSMQ。
我想在我的ASP.NET应用程序上监视此响应MSMQ。我该怎么做?
答案 0 :(得分:0)
您必须执行以下操作才能阅读MSMQ消息:
private static MyMessage RecieveMessage()
{
if (!MessageQueue.Exists(QueueName))
{
return null;
}
using (var msmq = new MessageQueue(QueueName))
{
msmq.Formatter = new XmlMessageFormatter(new Type[] { typeof(MyMessage) });
var message = msmq.Receive();
return message != null && message.Body is MyMessage ? (MyMessage)message.Body : null;
}
}
对您来说究竟是什么问题?检查一下sample MSMQ project,也许它可以说明应该如何制作。