net 網站新建webservice,客戶端調用,用法詳解

關於新建webservice的例子,這裏不贅述,重點是調用過程中,一些注意事項

.net記得添加服務引用,

.net記得添加服務引用,

.net記得添加服務引用,

新建服務,很大程度上是要跨平臺使用,因此並不能直接返回諸如,datarow,datatable之類的數據集合,

跨平臺序列化

跨平臺序列化

跨平臺序列化

解決方法是,序列化,某位大神說過,跨平臺,不序列化,需要面壁思過,

這裏實現的方式,轉爲bytes[],同時需要注意,進行解壓步驟,數據量大,節省寬帶,

服務端,和客戶端 解壓縮,要一致

服務端,和客戶端 解壓縮,要一致

服務端,和客戶端 解壓縮,要一致

 

相關方法和代碼

 protected DBSERVICE.connDBSoapClient conn = new DBSERVICE.connDBSoapClient();
//.net 記得添加服務引用,才能調用
//.net 記得添加服務引用,才能調用
//.net 記得添加服務引用,才能調用

 /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="data">要序列化的對象</param>
        /// <returns>返回存放序列化後的數據緩衝區</returns>
        public byte[] Serialize(object data)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream rems = new MemoryStream();
            formatter.Serialize(rems, data);
            return rems.GetBuffer();
        }

        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="data">數據緩衝區</param>
        /// <returns>對象</returns>
        public object Deserialize( byte[] data)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream rems = new MemoryStream(data);
            data = null;
            return formatter.Deserialize(rems);
        }

//需要自己寫相關的壓縮,解壓方法,這裏採用的公司封裝的zip壓縮方式

//需要自己寫相關的壓縮,解壓方法,這裏採用的公司封裝的zip壓縮方式

//需要自己寫相關的壓縮,解壓方法,這裏採用的公司封裝的zip壓縮方式
   public  byte[] getbyte(DataSet dataSet)
    {
        DataSetSurrogate dss = new DataSetSurrogate(dataSet);
        BinaryFormatter ser = new BinaryFormatter();
        MemoryStream ms = new MemoryStream();
        ser.Serialize(ms, dss);
        byte[] buffer = ms.ToArray();
        byte[] zipBuffer = new CompressionHelper(CompressionLevel.BestSpeed).CompressToBytes(buffer);
        return zipBuffer;
    }
        public DataSet getdateset(byte[] zipBuffer)
        {
            byte[] buffer = new CompressionHelper(CompressionLevel.BestSpeed).DecompressToBytes(zipBuffer);
            MemoryStream br = new MemoryStream(buffer);
            BinaryFormatter bf = new BinaryFormatter();
            object o = bf.Deserialize(br);
            DataSetSurrogate sds = (DataSetSurrogate)o;
            DataSet ds = sds.ConvertToDataSet();
            br.Close();
            return ds;
        }

//調用相關
conn.Insert(Serialize(ht), "DW_PHONE");

  //select * from DW_PHONE
            byte[] bys = conn.GetDataTable(@"select  b.RealName 溝通人員,case when [Type]='2' then '呼出' else '來電' end 類型,
case when a.state=1 then '已接' else '未接' end 狀態,
cast(Times/60 as varchar(8))+'分'+cast(Times%60 as varchar(8))+'秒' 溝通時長,FollowAbstract 產品摘要,AbstractContent 內容摘要 from DW_PHONE a
left join Tb_Common_User b on a.WorkNo=b.WorkNO");
            DataTable dt = getdateset(bys).Tables[0];

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章