ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:62.50KB ,
资源ID:5926689      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-5926689.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(怎样提高webservice的性能(打印).doc)为本站会员(HR专家)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

怎样提高webservice的性能(打印).doc

1、.怎样提高WebService的性能服务器端WebService程序using System.Runtime.Serialization.Formatters.Binary;using System.IO;using System.IO.Compression;using System.Data.SqlClient;public class Service1 : System.Web.Services.WebServiceWebMethod(Description = “直接返回 DataSet 对象。“)public DataSet GetNorthwindDataSet()string s

2、ql = “SELECT * FROM XT_TEXT“;SqlConnection conn = new SqlConnection(“Server=60.28.25.58;DataBase=s168593;user id=s168593;password=h0y+FeC*;“);conn.Open();SqlDataAdapter dataadapter = new SqlDataAdapter(sql, conn);DataSet ds = new DataSet();dataadapter.Fill(ds, “XT_TEXT“);conn.Close();return ds;WebMe

3、thod(Description = “返回 DataSet 对象用 Binary 序列化后的字节数组。“)public byte GetDataSetBytes()DataSet dataSet = GetNorthwindDataSet();BinaryFormatter ser = new BinaryFormatter();MemoryStream ms = new MemoryStream();ser.Serialize(ms, dataSet);byte buffer = ms.ToArray();return buffer;WebMethod(Description = “返回

4、DataSetSurrogate 对象用 Binary 序列化后的字节数组。“)public byte GetDataSetSurrogateBytes()DataSet dataSet = GetNorthwindDataSet();DataSetSurrogate dss = new DataSetSurrogate(dataSet);BinaryFormatter ser = new BinaryFormatter();MemoryStream ms = new MemoryStream();ser.Serialize(ms, dss);byte buffer = ms.ToArray(

5、);return buffer;WebMethod(Description = “返回 DataSetSurrogate 对象用 Binary 序列化并 Zip 压缩后的字节数组。“).public byte GetDataSetSurrogateZipBytes()DataSet dataSet = GetNorthwindDataSet();DataSetSurrogate dss = new DataSetSurrogate(dataSet);BinaryFormatter ser = new BinaryFormatter();MemoryStream ms = new MemoryS

6、tream();ser.Serialize(ms, dss);byte buffer = ms.ToArray();byte zipBuffer = Compress(buffer);return zipBuffer;public byte Compress(byte data)tryMemoryStream ms = new MemoryStream();Stream zipStream = null;zipStream = new GZipStream(ms, CompressionMode.Compress, true);zipStream.Write(data, 0, data.Len

7、gth);zipStream.Close();ms.Position = 0;byte compressed_data = new bytems.Length;ms.Read(compressed_data, 0, int.Parse(ms.Length.ToString();return compressed_data;catchreturn null;客户端WebService程序private void button1_Click(object sender, EventArgs e)com.dzbsoft.www.Service1 ds = new com.dzbsoft.www.Se

8、rvice1();DateTime dtBegin = DateTime.Now;DataSet dataSet = ds.GetNorthwindDataSet();this.label1.Text = string.Format(“耗时:0“, DateTime.Now - dtBegin);binddata(dataSet);private void button2_Click(object sender, EventArgs e)com.dzbsoft.www.Service1 ds = new com.dzbsoft.www.Service1();DateTime dtBegin =

9、 DateTime.Now;byte buffer = ds.GetDataSetBytes();BinaryFormatter ser = new BinaryFormatter();.DataSet dataSet = ser.Deserialize(new MemoryStream(buffer) as DataSet;this.label2.Text = string.Format(“耗时:0“, DateTime.Now - dtBegin) + “ “ + buffer.Length;binddata(dataSet);private void button3_Click(obje

10、ct sender, EventArgs e)com.dzbsoft.www.Service1 ds = new com.dzbsoft.www.Service1();DateTime dtBegin = DateTime.Now;byte buffer = ds.GetDataSetSurrogateBytes();BinaryFormatter ser = new BinaryFormatter();DataSetSurrogate dss = ser.Deserialize(new MemoryStream(buffer) as DataSetSurrogate;DataSet data

11、Set = dss.ConvertToDataSet();this.label3.Text = string.Format(“耗时:0“, DateTime.Now - dtBegin) + “ “ + buffer.Length;binddata(dataSet);private void button4_Click(object sender, EventArgs e)com.dzbsoft.www.Service1 ds = new com.dzbsoft.www.Service1();DateTime dtBegin = DateTime.Now;byte zipBuffer = ds

12、.GetDataSetSurrogateZipBytes();byte buffer = UnZipClass.Decompress(zipBuffer);BinaryFormatter ser = new BinaryFormatter();DataSetSurrogate dss = ser.Deserialize(new MemoryStream(buffer) as DataSetSurrogate;DataSet dataSet = dss.ConvertToDataSet();this.label4.Text = string.Format(“耗时:0“, DateTime.Now

13、 - dtBegin) + “ “ + zipBuffer.Length;binddata(dataSet);private void binddata(DataSet dataSet)this.dataGridView1.DataSource = dataSet.Tables0;this.label5.Text = “共计:“ + dataSet.Tables0.Rows.Count + “条记录“;客户端UnZipClass程序public static class UnZipClasspublic static byte Decompress(byte data)tryMemoryStr

14、eam ms = new MemoryStream(data);Stream zipStream = null;zipStream = new GZipStream(ms, CompressionMode.Decompress);byte dc_data = null;dc_data = ExtractBytesFromStream(zipStream, data.Length);return dc_data;catch.return null;public static byte ExtractBytesFromStream(Stream zipStream, int dataBlock)b

15、yte data = null;int totalBytesRead = 0;trywhile (true)Array.Resize(ref data, totalBytesRead + dataBlock + 1);int bytesRead = zipStream.Read(data, totalBytesRead, dataBlock);if (bytesRead = 0)break;totalBytesRead += bytesRead;Array.Resize(ref data, totalBytesRead);return data;catchreturn null;http:/

16、System;using System.Collections.Generic;using System.IO.Compression;using System.Text;using System.Data;using System.IO;using System.Runtime.Serialization;using System.Runtime.Serialization.Formatters.Binary;using KCSvrOpr.Encrypt;using System.Xml;namespace KCSvrOpr.DataFormat/ / 功 能:对数据的基本操作/ 作 者:B

17、QONE/ 创建日期:2007 年 04 月 17 日/ 更新作者:/ 更新日期:/ 添加功能:/ 描 述:包括数据的压缩,对象与 byte之间的转换/ 版 权:HN KC/ public class KCDataFormatter.public KCDataFormatter() / / 将 DataSet 格式化成字节数组 byte/ / DataSet 对象/ 字节数组 public static byte GetBinaryFormatData(DataSet dsOriginal)byte binaryDataResult = null;MemoryStream memStream

18、= new MemoryStream();IFormatter brFormatter = new BinaryFormatter();dsOriginal.RemotingFormat = SerializationFormat.Binary;brFormatter.Serialize(memStream, dsOriginal);binaryDataResult = memStream.ToArray();memStream.Close();memStream.Dispose();return binaryDataResult;/ / 将 DataSet 格式化成字节数组 byte,并且已

19、经经过压缩/ / DataSet 对象/ 字节数组 public static byte GetBinaryFormatDataCompress(DataSet dsOriginal)byte binaryDataResult = null;MemoryStream memStream = new MemoryStream();IFormatter brFormatter = new BinaryFormatter();dsOriginal.RemotingFormat = SerializationFormat.Binary;brFormatter.Serialize(memStream,

20、dsOriginal);binaryDataResult = memStream.ToArray();memStream.Close();memStream.Dispose();return Compress(binaryDataResult);/ / 解压数据/ / / public static byte Decompress(byte data)byte bData;MemoryStream ms = new MemoryStream();ms.Write(data, 0, data.Length);ms.Position = 0;GZipStream stream = new GZip

21、Stream(ms, CompressionMode.Decompress, true);byte buffer = new byte1024;MemoryStream temp = new MemoryStream();int read = stream.Read(buffer, 0, buffer.Length);while (read 0)temp.Write(buffer, 0, read);read = stream.Read(buffer, 0, buffer.Length);/必须把 stream 流关闭才能返回 ms 流数据,不然数据会不完整stream.Close();str

22、eam.Dispose();ms.Close();ms.Dispose();bData = temp.ToArray();temp.Close();temp.Dispose();return bData;./ / 压缩数据/ / / public static byte Compress(byte data)byte bData;MemoryStream ms = new MemoryStream();GZipStream stream = new GZipStream(ms, CompressionMode.Compress, true);stream.Write(data, 0, data

23、.Length);stream.Close();stream.Dispose();/必须把 stream 流关闭才能返回 ms 流数据,不然数据会不完整/并且解压缩方法 stream.Read(buffer, 0, buffer.Length)时会返回 0bData = ms.ToArray();ms.Close();ms.Dispose();return bData;/ / 将字节数组反序列化成 DataSet 对象/ / 字节数组/ DataSet 对象public static DataSet RetrieveDataSet(byte binaryData)DataSet dsOrigi

24、nal = null;MemoryStream memStream = new MemoryStream(binaryData);IFormatter brFormatter = new BinaryFormatter();Object obj = brFormatter.Deserialize(memStream);dsOriginal = (DataSet)obj;return dsOriginal;/ / 将字节数组反解压后序列化成 DataSet 对象/ / 字节数组/ DataSet 对象public static DataSet RetrieveDataSetDecompress(

25、byte binaryData)DataSet dsOriginal = null;MemoryStream memStream = new MemoryStream(Decompress(binaryData);IFormatter brFormatter = new BinaryFormatter();Object obj = brFormatter.Deserialize(memStream);dsOriginal = (DataSet)obj;return dsOriginal;/ / 将 object 格式化成字节数组 byte/ / object 对象/ 字节数组 public s

26、tatic byte GetBinaryFormatData(object dsOriginal)byte binaryDataResult = null;MemoryStream memStream = new MemoryStream();IFormatter brFormatter = new BinaryFormatter();brFormatter.Serialize(memStream, dsOriginal);binaryDataResult = memStream.ToArray();.memStream.Close();memStream.Dispose();return b

27、inaryDataResult;/ / 将 objec 格式化成字节数组 byte,并压缩/ / object 对象/ 字节数组 public static byte GetBinaryFormatDataCompress(object dsOriginal)byte binaryDataResult = null;MemoryStream memStream = new MemoryStream();IFormatter brFormatter = new BinaryFormatter();brFormatter.Serialize(memStream, dsOriginal);binar

28、yDataResult = memStream.ToArray();memStream.Close();memStream.Dispose();return Compress(binaryDataResult);/ / 将字节数组反序列化成 object 对象/ / 字节数组/ object 对象public static object RetrieveObject(byte binaryData)MemoryStream memStream = new MemoryStream(binaryData);IFormatter brFormatter = new BinaryFormatter(

29、);Object obj = brFormatter.Deserialize(memStream);return obj;/ / 将字节数组解压后反序列化成 object 对象/ / 字节数组/ object 对象public static object RetrieveObjectDecompress(byte binaryData)MemoryStream memStream = new MemoryStream(Decompress(binaryData);IFormatter brFormatter = new BinaryFormatter();Object obj = brForm

30、atter.Deserialize(memStream);return obj;/ / 解密配置文件并读入到 xmldoc 中/ public static XmlNode DecryptConfigFile(string filePath)FileStream fs = new FileStream(filePath, FileMode.Open);XmlDocument m_XmlDoc = new XmlDocument();BinaryFormatter formatter = null;tryformatter = new BinaryFormatter();/ Deserializ

31、e the hashtable from the file and/ assign the reference to the local variable.m_XmlDoc.LoadXml(KCEncrypt.Decrypt(string)formatter.Deserialize(fs);return m_XmlDoc.DocumentElement;catch (SerializationException e).Console.WriteLine(“Failed to deserialize. Reason: “ + e.Message);throw;finallyfs.Close();

32、fs = null;/ / 加密密钥后再对文件字符进行加密/ public static void EncryptConfigFile(string filePath, string str)FileStream fs = new FileStream(filePath, FileMode.Create);BinaryFormatter formatter = new BinaryFormatter();tryformatter.Serialize(fs, KCEncrypt.Encrypt(str);catch (SerializationException e)Console.WriteLine(“Failed to serialize. Reason: “ + e.Message);throw;finallyfs.Close();fs = null;

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报