技术开发 频道

WinCE数据通讯之Web Service篇

  添加终端设备调用

//webmethod序列化数据
        private void btnSerial_Click(object sender, EventArgs e)
        {
            
try
            {
                
this.dtGrid.DataSource = null;
                DataSet ds
= new DataSet();
                DateTime dtBegin
= DateTime.Now;
                
byte[] datas = ws.GetDataSetBytes();
                DateTime dtDown
= DateTime.Now;

                ds
= (DataSet)ComZipClass.zip.objXmlDeserialize(datas, typeof(DataSet));
                DateTime dtSerial
= DateTime.Now;
                
this.dtGrid.DataSource = ds.Tables[0];
                MessageBox.Show(
string.Format("下载耗时:{0},解压序列化数据耗时:{1},绑定数据耗时:{2},数据量:{3}",
                dtDown
- dtBegin,dtSerial-dtDown, DateTime.Now - dtDown, datas.Length));
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
//序列化并压缩BZIP后数据
        private void btnBZip_Click(object sender, EventArgs e)
        {
            
try
            {
                
this.dtGrid.DataSource = null;
                DataSet ds
= new DataSet();
                DateTime dtBegin
= DateTime.Now;
                
byte[] datas = ws.GetBZiipCompress();
                DateTime dtDown
= DateTime.Now;
                
byte[] uzip = ComZipClass.zip.BZipDeCompress(datas);
                DateTime dtUnzip
= DateTime.Now;
                ds
= (DataSet)ComZipClass.zip.objXmlDeserialize(uzip, typeof(DataSet));
                DateTime dtSerial
= DateTime.Now;
                
this.dtGrid.DataSource = ds.Tables[0];
                 MessageBox.Show(
string.Format("下载耗时:{0},解压BZIP耗时:{1},解压序列化耗时:{2},绑定数据耗时:{3},数据量:{4}",
                dtDown
- dtBegin, dtUnzip - dtDown, dtSerial - dtUnzip, DateTime.Now - dtSerial, datas.Length));
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
//序列化并压缩Deflate后数据
        private void btnDeflater_Click(object sender, EventArgs e)
        {
            
try
            {
                
this.dtGrid.DataSource = null;
                DataSet ds
= new DataSet();
                DateTime dtBegin
= DateTime.Now;
                
byte[] datas = ws.GetDeflaterCompress();
                DateTime dtDown
= DateTime.Now;
                
byte[] uzip = ComZipClass.zip.DeflaterDeCompress(datas);
                DateTime dtUnzip
= DateTime.Now;
                ds
= (DataSet)ComZipClass.zip.objXmlDeserialize(uzip, typeof(DataSet));
                DateTime dtSerial
= DateTime.Now;
                
this.dtGrid.DataSource = ds.Tables[0];
                MessageBox.Show(
string.Format("下载耗时:{0},解压Deflater耗时:{1},解压序列化耗时:{2},绑定数据耗时:{3},数据量:{4}",
               dtDown
- dtBegin, dtUnzip - dtDown, dtSerial - dtUnzip, DateTime.Now - dtSerial, datas.Length));
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
//序列化并压缩GZIP后数据
        private void btnGZip_Click(object sender, EventArgs e)
        {
            
try
            {
                
this.dtGrid.DataSource = null;
                DataSet ds
= new DataSet();
                DateTime dtBegin
= DateTime.Now;
                
byte[] datas = ws.GetGZipCompress();
                DateTime dtDown
= DateTime.Now;
                
byte[] uzip = ComZipClass.zip.GZipDeCompress(datas);
                DateTime dtUnzip
= DateTime.Now;
                ds
= (DataSet)ComZipClass.zip.objXmlDeserialize(uzip, typeof(DataSet));
                DateTime dtSerial
= DateTime.Now;
                
this.dtGrid.DataSource = ds.Tables[0];
                MessageBox.Show(
string.Format("下载耗时:{0},解压GZIP耗时:{1},解压序列化耗时:{2},绑定数据耗时:{3},数据量:{4}",
               dtDown
- dtBegin, dtUnzip - dtDown, dtSerial - dtUnzip, DateTime.Now - dtSerial, datas.Length));
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
//序列化并压缩ZIP后数据
        private void btnZip_Click(object sender, EventArgs e)
        {
            
try
            {
                
this.dtGrid.DataSource = null;
                DataSet ds
= new DataSet();
                DateTime dtBegin
= DateTime.Now;
                
byte[] datas = ws.GetZipCompress();
                DateTime dtDown
= DateTime.Now;
                
byte[] uzip = ComZipClass.zip.ZipDeCompress(datas);
                DateTime dtUnzip
= DateTime.Now;
                ds
= (DataSet)ComZipClass.zip.objXmlDeserialize(uzip, typeof(DataSet));
                DateTime dtSerial
= DateTime.Now;
                
this.dtGrid.DataSource = ds.Tables[0];
                MessageBox.Show(
string.Format("下载耗时:{0},解压ZIP耗时:{1},解压序列化耗时:{2},绑定数据耗时:{3},数据量:{4}",
               dtDown
- dtBegin, dtUnzip - dtDown, dtSerial - dtUnzip, DateTime.Now - dtSerial, datas.Length));
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

  几个测试压缩数据dataset :268128;serial:269199;bzip:94561;Deflater:107049;gzip:108276;zip:108408;

0
相关文章