//本地消息发送 二进制格式文件传输
try
{
this.localMessageQueue = new MessageQueue(local_mq.Text);
System.IO.FileStream inFile = new FileStream("d:\\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.Label = "[mp3音乐]";
//Msg.Body = mStr;
localMessageQueue.Send(Msg);
localMessageQueue.Close();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
//本地消息接收 二进制格式文件传输
//using System.Runtime.Serialization.Formatters.Binary;
this.localMessageQueue = new MessageQueue(local_mq.Text);
byte[] bytes=new byte[1024*1024*4];
System.Messaging.Message Msg = new System.Messaging.Message(bytes, new BinaryMessageFormatter());
//使用BinaryMessageFormatter这个类型进行串行化,默认情况下,这个属性不进行赋值的话就是XmlMessageFormatter
Msg = localMessageQueue.Receive();
IFormatter bf = new BinaryFormatter();
object obj = bf.Deserialize(Msg.BodyStream);
bytes= (byte[])obj;
//bytes= (byte[])Msg.Body;
//byte[] bytes = Convert.FromBase64String(pic);//声明一个byte[]用来存放Base64解码转换过来的数据流
//byte[] bytes = (byte[])Msg.Body;
//声明一个byte[]用来存放数据流
//创建文件流并保存
FileStream outfile = new System.IO.FileStream("C:\\zhou_xingchi.mp3", System.IO.FileMode.CreateNew);
outfile.Write(bytes, 0, (int)bytes.Length);
localMessageQueue.Close();
try
{
this.localMessageQueue = new MessageQueue(local_mq.Text);
System.IO.FileStream inFile = new FileStream("d:\\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.Label = "[mp3音乐]";
//Msg.Body = mStr;
localMessageQueue.Send(Msg);
localMessageQueue.Close();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
//本地消息接收 二进制格式文件传输
//using System.Runtime.Serialization.Formatters.Binary;
this.localMessageQueue = new MessageQueue(local_mq.Text);
byte[] bytes=new byte[1024*1024*4];
System.Messaging.Message Msg = new System.Messaging.Message(bytes, new BinaryMessageFormatter());
//使用BinaryMessageFormatter这个类型进行串行化,默认情况下,这个属性不进行赋值的话就是XmlMessageFormatter
Msg = localMessageQueue.Receive();
IFormatter bf = new BinaryFormatter();
object obj = bf.Deserialize(Msg.BodyStream);
bytes= (byte[])obj;
//bytes= (byte[])Msg.Body;
//byte[] bytes = Convert.FromBase64String(pic);//声明一个byte[]用来存放Base64解码转换过来的数据流
//byte[] bytes = (byte[])Msg.Body;
//声明一个byte[]用来存放数据流
//创建文件流并保存
FileStream outfile = new System.IO.FileStream("C:\\zhou_xingchi.mp3", System.IO.FileMode.CreateNew);
outfile.Write(bytes, 0, (int)bytes.Length);
localMessageQueue.Close();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货