微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Webservice之Dataset传输[客户端]

using System.IO;
using System.IO.Compression;
using System.Data;
using System.Data.sqlClient;
using System.Runtime.Serialization.Formatters.Binary;

//DataSet
        #region
private void BindDataSet(DataSet ds)
    {
        //this.GridView1.DataSource = null;
        //this.GridView1.DataSource = ds.Tables[0];
        //this.GridView1.DataBind();
    }
    protected void Button1_Click(object sender,EventArgs e)
    {
        localhost. Service1 ws = new localhost.Service1();
        DateTime dtBegin = DateTime .Now;
        DataSet ds = ws.GetDataSet();
        this.Label1.Text = string .Format("耗时 : {0}",DateTime.Now-dtBegin);
        BindDataSet(ds);
    }
    protected void Button2_Click(object sender,EventArgs e)
    {
        localhost. Service1 ws = new localhost.Service1();
        DateTime dtBegin = DateTime .Now;
        byte[] buffer = ws.GetDataSetBytes();
        BinaryFormatter ser = new BinaryFormatter();
        DataSet ds = ser.Deserialize(new MemoryStream(buffer)) as DataSet;
        this.Label2.Text = string .Format("耗时 : {0};   大小:{1}",DateTime.Now - dtBegin,buffer.Length.ToString());
        BindDataSet(ds);
    }
    protected void Button3_Click(object sender,EventArgs e)
    {
        localhost. Service1 ws = new localhost.Service1();
        DateTime dtBegin = DateTime .Now;
        byte[] buffer = ws.GetDataSetSurrogateBytes();
        BinaryFormatter ser = new BinaryFormatter();
        dss. DataSetSurrogate dss = ser.Deserialize(new MemoryStream(buffer)) as dss.DataSetSurrogate;
        DataSet ds = dss.ConvertToDataSet();
        this.Label3.Text = string .Format("耗时 : {0};   大小:{1}",buffer.Length.ToString());
        BindDataSet(ds);
    }
    protected void Button4_Click(object sender,EventArgs e)
    {
        localhost. Service1 ws = new localhost.Service1();
        DateTime dtBegin = DateTime .Now;
        byte[] zipBuffer = ws.GetDataSetSurrogateZipBytes();
        byte[] buffer = UnZipClass .Decompress(zipBuffer);
        BinaryFormatter ser = new BinaryFormatter();
        dss. DataSetSurrogate dss = ser.Deserialize(new MemoryStream(buffer)) as dss.DataSetSurrogate;
        DataSet ds = dss.ConvertToDataSet();
        this.Label4.Text = string .Format("耗时 : {0};   大小:{1}",zipBuffer.Length.ToString());
        BindDataSet(ds);
    }
  #endregion

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐