标签:
//写入消息 Message message = proxy.GetDataXml(); FileStream stream = new FileStream(@"c:/log.xml", FileMode.Create); XmlDictionaryWriter xdr = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8); message.WriteBodyContents(xdr); //message.WriteBody(xdr); //message.WriteMessage(xdr); xdr.Flush(); Console.WriteLine("消息写入成功");
2. 使用WriteBody写入消息结构,写入后我们可以看到log.xml的文件结构如下:
3. 使用WriteMessage写入消息结构,写入后我们可以看到log.xml的文件结构如下
//读取消息 Message message = proxy.GetDataObject(); User user = message.GetBody<User>(); Console.WriteLine("读取消息信息成功"); Console.WriteLine(user.ID+"->"+user.Name);
运行结果显示如下:
//复制消息 Message message = proxy.GetDataXml(); MessageBuffer mb = message.CreateBufferedCopy(65536); FileStream stream = new FileStream(@"c:/log.xml", FileMode.Create); mb.WriteMessage(stream); stream.Flush(); Console.WriteLine("复制消息信息成功");
运行后,log.xml文件结构如下:
//访问消息的其他部分 Message message = proxy.GetDataEmpty(); Console.WriteLine("Version:" + message.Version.ToString()); Console.WriteLine("State:" + message.State.ToString()); Console.WriteLine("IsEmpty:" + message.IsEmpty.ToString()); Console.WriteLine("IsFault:" + message.IsFault.ToString()); Console.WriteLine("消息Headers包含的属性如下:"); foreach (MessageHeaderInfo item in message.Headers) { Console.WriteLine(item.Name); }
运行结果如下:
标签:
原文地址:http://www.cnblogs.com/wangweimutou/p/4488510.html