.net WebService 大数据量时性能的提高
作者:佚名    ASP.NET网站开发编辑:admin   更新时间:2022-07-23
.net WebService 大数据量时性能的提高
1.直接返回DataSet对象
C#代码
- [WebMethod(Description="直接返回DataSet对象")]
- publicDataSetGetUserListDateSet()
- {
- SqlConnectionsqlCon=newSqlConnection("DataSource=.,1444;InitialCatalog=StudyNet;PersistSecurityInfo=True;UserID=**;PassWord=******");
- SqlCommandcmd=newSqlCommand();
- cmd.Connection=sqlCon;
- cmd.CommandText="select*fromT_User";
- SqlDataAdapterda=newSqlDataAdapter(cmd);
- DataSetds=newDataSet();
- da.Fill(ds);
- returnds;
- }
2.返回DataSet对象用Binary序列化后的字节数组C#代码
- [WebMethod(Description="返回DataSet对象用Binary序列化后的字节数组")]
- publicbyte[]GetUserListDateSetBytes()
- {
- DataSetds=GetUserListDateSet();
- //序列化
- BinaryFormatterser=newBinaryFormatter();
- MemoryStreamstream=newMemoryStream();
- ser.Serialize(stream,ds);
- returnstream.GetBuffer();
- }
3.返回DataSetSurrogate对象用Binary序列化后的字节数组C#代码
- [WebMethod(Description="返回DataSetSurrogate对象用Binary序列化后的字节数组")]
- publicbyte[]GetUserListDateSetSurrogateBytes()
- {
- DataSetds=GetUserListDateSet();
- DataSetSurrogatedss=newDataSetSurrogate(ds);
- //序列化
- BinaryFormatterser=newBinaryFormatter();
- MemoryStreamstream=newMemoryStream();
- ser.Serialize(stream,dss);
- returnstream.GetBuffer();
- }
4.返回DataSetSurrogate对象用Binary序列化并Zip压缩后的字节数组C#代码
- [WebMethod(Description="返回DataSetSurrogate对象用Binary序列化并ZIP压缩后的字节数组")]
- publicbyte[]GetUserListDateSetSurrogateZipBytes()
- {
- DataSetds=GetUserListDateSet();
- DataSetSurrogatedss=newDataSetSurrogate(ds);
- //序列化
- BinaryFormatterser=newBinaryFormatter();
- MemoryStreamstream=newMemoryStream();
- ser.Serialize(stream,dss);
- //压缩
- returnComPRess(stream.ToArray());
- }
- ///<summary>
- ///压缩数据
- ///</summary>
- ///<paramname="data"></param>
- ///<returns></returns>
- publicbyte[]Compress(byte[]data)
- {
- MemoryStreamms=newMemoryStream();
- GZipStreamzipStream=newGZipStream(ms,CompressionMode.Compress);
- zipStream.Write(data,0,data.Length);//将数据压缩并写到基础流中
- zipStream.Close();
- returnms.ToArray();
- }
5.结果图
- .net_webservice大数量时性能的提供.rar (119.2 KB)
- 下载次数: 26
- DataSetSurrogate.rar (8.7 KB)