求教关于消息队列的问题

heavenkiller 2004-03-20 09:00:52
using System;
using System.Messaging;

namespace MessageTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
// [STAThread]
// static void Main(string[] args)
// {
// //
// // TODO: 在此处添加代码以启动应用程序
// //
// }

// This class represents an object the following example
// sends to a queue and receives from a queue.
public class Order
{
public int orderId;
public DateTime orderTime;
};

/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{

//**************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a queue.
//**************************************************

public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();

// Send a message to a queue.
myNewQueue.SendMessage();

// Receive a message from a queue.
myNewQueue.ReceiveMessage();

return;
}


//**************************************************
// Sends an Order to a queue.
//**************************************************

public void SendMessage()
{

// Create a new order and set values.
Order sentOrder = new Order();
sentOrder.orderId = 3;
sentOrder.orderTime = DateTime.Now;

// Connect to a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");

// Send the Order to the queue.
myQueue.Send(sentOrder);

return;
}


//**************************************************
// Receives a message containing an Order.
//**************************************************

public void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");

// Set the formatter to indicate body contains an Order.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(Order)});

try
{
// Receive and format the message.
Message myMessage = myQueue.Receive();
Order myOrder = (Order)myMessage.Body;

// Display message information.
Console.WriteLine("Order ID: " +
myOrder.orderId.ToString());
Console.WriteLine("Sent: " +
myOrder.orderTime.ToString());
}

catch (MessageQueueException)
{
// Handle Message Queuing exceptions.
}

// Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}

// Catch other exceptions as necessary.

return;
}
}

}
}



可是老是出现如下错误:
未处理的“System.Messaging.MessageQueueException”类型的异常出现在 system.messaging.dll 中。

其他信息: 外部组件发生异常

******************************************
请大家帮帮忙,急用!!!!!!!!!!!!!!!!!!!!!!!
*****************************************
...全文
75 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
linaren 2004-03-20
  • 打赏
  • 举报
回复
怎么有两个main()函数?
showtimenow 2004-03-20
  • 打赏
  • 举报
回复
首先你要有消息队列服务
在安装IIS的时候选择即可
marvelstack 2004-03-20
  • 打赏
  • 举报
回复
楼主有没设置MSMQ呀。

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧