[英].net MSMQ desktop application
我正在嘗試學習MSMQ,並且從做兩個簡單的控制台應用程序開始。 發射器和接收器。
首先,這是發射機代碼:
static void Main(string[] args)
{
try
{
if (MessageQueue.Exists(path))
{
mqueue = new MessageQueue(path);
}
else
{
mqueue = MessageQueue.Create(path);
}
Timer timer = new Timer(timerCallback, null, 3000, 3000);
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
System.Console.ReadLine();
}
}
static void timerCallback(object state)
{
Student student = new Student(randomString(), randomString(), randomString());
mqueue.Send(student);
System.Console.WriteLine("sent: {0}", student.ToString());
}
和接收者:
static void Main(string[] args)
{
try
{
if (MessageQueue.Exists(path))
{
mqueue = new MessageQueue(path);
}
else
{
mqueue = MessageQueue.Create(path);
}
Type [] supportedTypes = {typeof(Student)};
mqueue.Formatter = new XmlMessageFormatter(supportedTypes);
mqueue.BeginReceive(new TimeSpan(0,0,5000), mqueue, new AsyncCallback(messageReceived));
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
System.Console.ReadLine();
}
}
該應用程序運行正常,但我想將通信通道更改為TcpChannel/ HttpChannel
。 知道我該怎么做嗎?
CodeProject:使用MSMQ創建WCF服務會為您提供有關msmq的不錯的教程。 一些搜索使我得出結論,這僅在wcf中可行,但我可能是錯的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.