DataSet序列化傳送

摘要:DataSet序列化傳送

送出前作以下處理:
 
        private byte[] DataSetToByte(DataSet dsResult)
        {
            if (dsResult == null) return null;
            dsResult.RemotingFormat = SerializationFormat.Binary;
            using (MemoryStream ms = new MemoryStream())
            {
                (new BinaryFormatter()).Serialize(ms, dsResult);
                return ms.ToArray();
            }
        }
 
 
收到時作以下處理:
        private static DataSet ByteToDataSet(byte[] Rev)
        {
            if (Rev == null) return null;
            using (MemoryStream ms = new MemoryStream(Rev))
            {
                return (DataSet)(new BinaryFormatter()).Deserialize(ms);
            }
        }
 
 
序列化後的資料量較小,可以省頻寬