コード例 #1
0
 private static MemoryStream WriteName(Name name)
 {
     var ms = new MemoryStream();
     var binary = XmlDictionaryWriter.CreateBinaryWriter(ms);
     var ser = new DataContractSerializer(typeof(Name));
     ser.WriteObject(binary, name);
     binary.Flush(); // Flush had to be added!
     return ms;
 }
コード例 #2
0
        static void Main(string[] args)
        {
            var name = new Name { FullName = "John Doe" };
            var ms = WriteName(name);

            ms.Position = 0;
            var sr = new StreamReader(ms);
            Console.WriteLine(sr.ReadToEnd());

            Console.ReadKey();
        }