/**//// <summary> /// Method for users data query with binaryFormatter /// </summary> /// <param name="err"></param> /// <returns></returns> public byte[] BinaryUserSelect(ref string err) { ClearCommand(); m_commandStringBuilder.Append("SELECT * FROM t_Users ;"); DataSet dsResult = new DataSet(); byte[] bArrayResult = null; try { dsResult = SqlHelper.ExecuteDataset(m_currentConnectionString, CommandType.Text, m_commandStringBuilder.ToString()); // 上面都是取数据的,无需关心.二进制压缩数据集是下面一小段 dsResult.RemotingFormat = SerializationFormat.Binary; MemoryStream ms = new MemoryStream(); IFormatter bf = new BinaryFormatter(); bf.Serialize(ms, dsResult); bArrayResult = ms.ToArray(); ms.Close(); // } catch (Exception ee) { err = ee.ToString(); } return bArrayResult; }
2. 通过WebService把byte[]格式的数据发送到客户端,这里就是WebService自己的事情了,我们无需关心
3.客户端接收到byte[]格式的数据,对其进行反序列化,得到数据集,进行客户端操作.
/**//// <summary> /// Get user data with Binary format /// </summary> /// <returns></returns> public DataSet GetBinaryUserData() { string err = ""; byte[] bUserData = svc.ByteArrayUserSelect(ref err); if (err != "") { MessageBox.Show(err); err = ""; return null; } // 反序列化的过程 MemoryStream ms = new MemoryStream(bUserData); IFormatter bf = new BinaryFormatter(); object obj = bf.Deserialize(ms); DataSet dsResult = (DataSet)obj; // ms.Close(); return dsResult; }