成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WebServices返回?cái)?shù)據(jù)的4種方法橫向比較

企業(yè)動(dòng)態(tài)
作者在與其他程序員進(jìn)行交流時(shí)長(zhǎng)聽(tīng)到WebServices性能特別慢的抱怨,那么究竟有多慢?本文將為大家進(jìn)行一個(gè)橫向的比較。

以前經(jīng)常在群里聽(tīng)到朋友們說(shuō)WebServices的性能特別的慢,說(shuō)的如何如何。說(shuō)實(shí)話(huà),WebServices的確比調(diào)用本地?cái)?shù)據(jù)要慢一些,可是究竟有多慢,真的如朋友們說(shuō)的那么難以忍受嗎?我個(gè)人感覺(jué),多半原因在處理的方式上。讓我們親自編寫(xiě)測(cè)試代碼,來(lái)證明這一切吧。文章由于是我一段時(shí)間的總結(jié)篇,因此難免參雜個(gè)人主觀因素,說(shuō)的不對(duì)的地方,還請(qǐng)多多批評(píng)。以下我們主要從調(diào)用WebServices的方法的特點(diǎn)、應(yīng)用場(chǎng)景、測(cè)試結(jié)果三個(gè)方面來(lái)進(jìn)行下說(shuō)明分析。

1. 直接返回DataSet對(duì)象

特點(diǎn):直接返回DataSet對(duì)象。

應(yīng)用場(chǎng)景:1.內(nèi)網(wǎng)。2.外網(wǎng)且數(shù)據(jù)量在kb級(jí)別時(shí)。

2.返回DataSet對(duì)象用Binary序列化后的字節(jié)數(shù)組

特點(diǎn):字節(jié)數(shù)組流的處理模式。

應(yīng)用場(chǎng)景:較大數(shù)據(jù)交換。

3.返回DataSetSurrogate對(duì)象用Binary 序列化后的字節(jié)數(shù)組

特點(diǎn):使用微軟提供的開(kāi)源組件進(jìn)行序列化,依然是字節(jié)流的處理模式。詳情請(qǐng)參考:http://support.microsoft.com/kb/829740/zh-cn

應(yīng)用場(chǎng)景: 較大數(shù)據(jù)交換。

4.返回DataSetSurrogate對(duì)象用Binary 序列化并Zip壓縮后的字節(jié)數(shù)組

特點(diǎn):使用微軟提供的開(kāi)源組件對(duì)字節(jié)流數(shù)組進(jìn)行壓縮后傳遞,依然是字節(jié)流的處理模式。詳情請(qǐng)參考:http://support.microsoft.com/kb/829740/zh-cn

應(yīng)用場(chǎng)景:外網(wǎng)環(huán)境需要進(jìn)行大數(shù)據(jù)量網(wǎng)絡(luò)數(shù)據(jù)傳遞時(shí),建議采用此種方法。也是筆者強(qiáng)烈向大家推薦使用的一種方法。

WebServices的代碼如下:

WebServicesusing System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;


using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization.Formatters.Binary;
namespace WebService1
{
///
/// Service1 的摘要說(shuō)明
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod(Description="直接返回DataSet對(duì)象")]
public DataSet GetDataSet()
{
string sql = "select * from Customers";
Database db = DatabaseFactory.CreateDatabase();
DataSet ds = db.ExecuteDataSet(CommandType.Text,sql);
return ds;
}

[WebMethod(Description = "返回DataSet對(duì)象用Binary序列化后的字節(jié)數(shù)組")]
public byte[] GetBytes()
{
DataSet ds = GetDataSet();
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, ds);
byte[] buffer = ms.ToArray();
return buffer;
}

[WebMethod(Description = "返回DataSetSurrogate對(duì)象用Binary序列化后的字節(jié)數(shù)組")]
public byte[] GetDataSetSurrogateBytes()
{
DataSet ds = GetDataSet();
DataSetSurrogate dss = new DataSetSurrogate(ds);
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms,dss);
byte[] buffer = ms.ToArray();
return buffer;
}

[WebMethod(Description = "返回DataSetSurrogate對(duì)象用Binary序列化并ZIP壓縮后的字節(jié)數(shù)組")]
public byte[] GetDataSetSurrogateZipBytes()
{
DataSet DS = GetDataSet();
DataSetSurrogate dss = new DataSetSurrogate(DS);
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, dss);
byte[] buffer = ms.ToArray();
byte[] Zipbuffer = Compress(buffer);
return Zipbuffer;
}

//壓縮壓縮后的字節(jié)數(shù)組
public byte[] Compress(byte[] data)
{
MemoryStream ms = new MemoryStream();
Stream zipStream = new GZipStream(ms, CompressionMode.Compress, true);
zipStream.Write(data, >0, data.Length);
zipStream.Close();
ms.Position = >0;
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, >0,int.Parse(ms.Length.ToString()));
return buffer;
}
}
}

客戶(hù)端調(diào)用WebServices的代碼如下:

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebServicesClient.localhost;
using System.Data;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Diagnostics;
namespace WebServicesClient
{
public partial class _Default : System.Web.UI.Page
{
Service1 s = new Service1();
protected void Page_Load(object sender, EventArgs e)
{

}

//直接返回DataSet對(duì)象
protected void Button1_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
DataSet ds = s.GetDataSet();
GridView1.DataSource = ds.Tables[>0].DefaultView;
GridView1.DataBind();
sw.Stop();
Label1.Text = string.Format("耗時(shí):{0}毫秒", sw.ElapsedMilliseconds.ToString());
}

//得到DataSet對(duì)象用Binary序列化后的字節(jié)數(shù)組
protected void Button2_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
byte[] buffer = s.GetBytes();
BinaryFormatter bf = new BinaryFormatter();
DataSet ds = bf.Deserialize(new MemoryStream(buffer)) as DataSet;
GridView1.DataSource = ds.Tables[>0].DefaultView;
GridView1.DataBind();
sw.Stop();
Label2.Text = string.Format("耗時(shí):{1}毫秒;數(shù)據(jù)大小:{0}", buffer.Length.ToString(), sw.ElapsedMilliseconds.ToString());
}
//得到DataSetSurrogate對(duì)象用Binary序列化后的字節(jié)數(shù)組
protected void Button3_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
byte[] buffer = s.GetDataSetSurrogateBytes();
BinaryFormatter bf = new BinaryFormatter();
DataSetSurrogate dss = bf.Deserialize(new MemoryStream(buffer)) as DataSetSurrogate;
DataSet ds = dss.ConvertToDataSet();
GridView1.DataSource = ds.Tables[>0].DefaultView;
GridView1.DataBind();
sw.Stop();
Label3.Text = string.Format("耗時(shí):{1}毫秒;數(shù)據(jù)大小:{0}", buffer.Length.ToString(), sw.ElapsedMilliseconds.ToString());
}
//得到DataSetSurrogate對(duì)象用Binary序列化并ZIP壓縮后的字節(jié)數(shù)組
protected void Button4_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
byte[] zipBuffer = s.GetDataSetSurrogateZipBytes();
byte[] buffer = UnZip.Decompress(zipBuffer);
BinaryFormatter bf = new BinaryFormatter();
DataSetSurrogate dss = bf.Deserialize(new MemoryStream(buffer)) as DataSetSurrogate;
DataSet ds = dss.ConvertToDataSet();
GridView1.DataSource = ds.Tables[>0].DefaultView;
GridView1.DataBind();
sw.Stop();

Label4.Text = string.Format("耗時(shí):{1}毫秒;數(shù)據(jù)大小:{0}",zipBuffer.Length.ToString(),sw.ElapsedMilliseconds.ToString());
}
}
}

測(cè)試的結(jié)果按照先后順序如下圖所示:


關(guān)于測(cè)試結(jié)果的特殊說(shuō)明,由于測(cè)試環(huán)境是在本地,數(shù)據(jù)量也不是很大,測(cè)試的結(jié)果離實(shí)際情況還不是很接近,如果大家有條件的話(huà),可以測(cè)試一下,同時(shí)希望把測(cè)試的結(jié)果提供給大家參考。

最后,為了方便大家,這里還提供了源碼下載,下載地址如下:

/Files/wlb/WebServiceSummary.rar

關(guān)于源代碼的特殊說(shuō)明:筆者這里的開(kāi)發(fā)環(huán)境為VS2008中文版sp1+SQLServer2008sp1。數(shù)據(jù)庫(kù)為Northwind數(shù)據(jù)庫(kù)。

【編輯推薦】

  1. Yahoo!揭開(kāi)Ajax WebServices的面紗
  2. Ajax,未來(lái)的WebServices
責(zé)任編輯:彭凡 來(lái)源: cnblogs
相關(guān)推薦

2018-05-29 11:20:18

數(shù)據(jù)中心方法省錢(qián)

2020-12-01 09:00:00

數(shù)據(jù)中心IT技術(shù)

2020-11-16 15:51:54

Kubernetes

2019-10-08 10:28:36

Python程序員鏡音雙子

2013-01-07 10:44:00

JavaScriptjQueryJS

2018-05-03 14:53:58

數(shù)據(jù)中心節(jié)省成本停機(jī)

2011-09-19 14:30:27

2011-06-22 15:21:08

XML

2017-06-09 06:29:24

數(shù)據(jù)中心服務(wù)器超融合

2017-04-28 15:07:10

網(wǎng)絡(luò)瓶頸問(wèn)題

2020-07-24 00:34:54

工業(yè)物聯(lián)網(wǎng)IIOT物聯(lián)網(wǎng)

2009-07-30 16:27:33

C#比較時(shí)間

2019-03-25 14:00:36

Linux主機(jī)名

2021-03-16 10:56:33

網(wǎng)絡(luò)安全首席信息安全官信息安全

2019-06-04 15:34:05

WindowsLinuxLinux命令

2018-10-29 05:23:37

2021-05-31 09:00:00

數(shù)據(jù)存儲(chǔ)存儲(chǔ)系統(tǒng)工具

2018-01-04 09:46:48

PHPHTTP

2017-05-12 09:11:39

2020-07-07 07:37:36

Integer源碼Java
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 日韩精品一区二区三区视频播放 | 亚洲精品视频一区二区三区 | 一区二区精品电影 | 男人av网 | 国产精品亚洲综合 | 国产激情免费视频 | 在线中文字幕亚洲 | av中文字幕网站 | 亚洲三级免费看 | 欧美精品tv | 免费三级av| 黑人巨大精品欧美一区二区免费 | 久久久免费 | 综合久久99 | 操网站 | 国内自拍第一页 | 中文字幕亚洲一区二区三区 | 欧美精品一区二区在线观看 | 国产91亚洲精品一区二区三区 | 国产精品日韩欧美一区二区三区 | 天堂久久一区 | 精品国产三级 | www国产成人免费观看视频,深夜成人网 | 成人性生交大片 | 国产美女在线观看 | 亚洲啪啪 | 国产激情三区 | 911影院| 国产中的精品av涩差av | 亚洲欧美另类在线观看 | 国产激情视频在线观看 | 国产在线高清 | 欧美视频三区 | 国产午夜精品一区二区三区 | 中文字幕日韩在线 | 色一级片| 免费国产视频在线观看 | 亚洲日韩第一页 | 日韩靠逼| 国产美女一区二区三区 | 国产精品美女久久久久久久网站 |