日期:2014-05-19  浏览次数:21040 次

msmq复杂格式消息发送和接收?
各位大虾,我想请教一下。net下利用msmq来发送和接收复杂消息的实现,比如我发送一个xml文件,在接收方应该如何实现接收,或则是二进制文件的发送和接收,请帮忙,谢谢!

------解决方案--------------------
顶啊
------解决方案--------------------
private void local_msg_send_Click(object sender, EventArgs e)
{
//本地消息发送 二进制格式文件传输
CreateQueue(@".\private$\TSS_MsmqTest");
CreateQueue(@".\private$\TSS_MsmqTest_QueueAdministration");
try
{
this.localMessageQueue = new MessageQueue(local_mq.Text);

System.IO.FileStream inFile = new FileStream("C:\\zhouxingchi.mp3", System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] binaryData = new byte[inFile.Length];
inFile.Read(binaryData, 0, (int)inFile.Length);
string mStr = Convert.ToBase64String(binaryData);
string hh = mStr;

System.Messaging.Message Msg = new System.Messaging.Message(binaryData, new BinaryMessageFormatter());
//使用BinaryMessageFormatter这个类型进行串行化,默认情况下,这个属性不进行赋值的话就是XmlMessageFormatter
//System.Messaging.Message Msg = new System.Messaging.Message();
// Msg.Formatter = new BinaryMessageFormatter();
Msg.AdministrationQueue = new MessageQueue(@".\private$\TSS_MsmqTest_QueueAdministration");
Msg.AcknowledgeType = AcknowledgeTypes.PositiveReceive | AcknowledgeTypes.PositiveArrival;
Msg.Label = "[mp3音乐]";
//Msg.Body = mStr;
localMessageQueue.Send(Msg);
localMessageQueue.Close();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());


}