服务端的代码如下:[WebMethod(Description = "DataSet")]
public DataSet GetAllGsmDataSet()
{
try
{
ConnectionProperty ConPro = new ConnectionProperty();
string ConnectionStr = "Data Source=192.168.0.52;Initial Catalog=GZGISDB;User ID=sa;Password=123123";
ConPro.ConnectionString = ConnectionStr;
ConPro.DatabaseType = DatabaseType.MSSqlServer;
IDataAccess DataAcess = DAFactory.CreateDataAccess(ConPro);
string Command = " SELECT [ID] ,[MSC_Name],[BSC_Name] ,[StationName] ,[ResidentialName] ,[X] ,[Y] ,[Name] FROM [GZGISDB].[dbo].[GsmInfo]";
DataSet DS = DataAcess.ExcuteDataSet(Command);
return DS;
}
catch
{
return null;
}
}
[WebMethod(Description="返回序列化的DataSet")]
public byte[] GetDataSetByte()
{
DataSet DS = GetAllGsmDataSet();
byte[] DSByte = Serilize(DS);
return DSByte;
}
[WebMethod(Description = "返回序列化的DataSetSurrograte")]
public byte[] GetAllGsmDataSetSurrograteByte()
{
try
{
DataSet DS = GetAllGsmDataSet();
DataSetSurrogate DSS = new DataSetSurrogate(DS);
byte[] _Data = Serilize(DSS);
return _Data;
}
catch
{
return null;
}
}
[WebMethod(Description = "返回序列化压缩后的DataSetSurrograte")]
public byte[] GetAllGsmDataSetSurrograteZipByte()
{
DataSet DS = GetAllGsmDataSet();
DataSetSurrogate DSS = new DataSetSurrogate(DS);
byte[] buffer = Serilize(DSS);
byte[] _Data = Compress(buffer);
return _Data;
}
/// <summary>
/// 序列化
/// </summary>
/// <param name="ob"></param>
/// <returns></returns>
private byte[] Serilize(object ob)
{
BinaryFormatter BinFor = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
BinFor.Serialize(ms, ob);
byte[] buffer = ms.ToArray();
return buffer;
}
private byte[] Compress(byte[] Data)
{
MemoryStream ms = new MemoryStream();
Stream Stream = null;
Stream = new GZipStream(ms, CompressionMode.Compress,true);
Stream.Write(Data, 0, Data.Length);
Stream.Close();
ms.Position = 0;
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, int.Parse(ms.Length.ToString()));
return buffer;
}
客户端我只是做了个简单的CS测试几种方法的速度: