问题描述
小弟在做一个C/S项目,要从客户端通过DATASET把数据用GZIP压缩用发到另一台机子的服务器端,求给出详细代码
解决方案
解决方案二:
//把DATASET序列化成二进制流,并压缩二进制流privatebyte[]GZipDataSet(DataSetds,refstringerrorinfo){try{BinaryFormatterser=newBinaryFormatter();MemoryStreamunCompressMS=newMemoryStream();ds.RemotingFormat=SerializationFormat.Binary;ser.Serialize(unCompressMS,ds);byte[]bytes=unCompressMS.ToArray();intlenbyte=bytes.Length;MemoryStreamcompressMs=newMemoryStream();GZipStreamcompressedStream=newGZipStream(compressMs,CompressionMode.Compress,true);compressedStream.Write(bytes,0,lenbyte);compressedStream.Close();unCompressMS.Close();compressMs.Close();byte[]zipbytes=compressMs.ToArray();intlen=zipbytes.Length;returnzipbytes;}catch(Exceptionex){errorinfo=ex.ToString();returnnull;}}//解压缩二进制流,并将解压缩后的二进制流还原成DataSetprivatestaticDataSetGetDataSetFromByte(byte[]data,refstringerrorinfo){try{MemoryStreaminput=newMemoryStream();input.Write(data,0,data.Length);input.Position=0;GZipStreamgzip=newGZipStream(input,CompressionMode.Decompress,true);MemoryStreamoutput=newMemoryStream();byte[]buff=newbyte[4096];intread=-1;read=gzip.Read(buff,0,buff.Length);while(read>0){output.Write(buff,0,read);read=gzip.Read(buff,0,buff.Length);}gzip.Close();byte[]rebytes=output.ToArray();output.Close();input.Close();MemoryStreamms=newMemoryStream(rebytes);BinaryFormatterbf=newBinaryFormatter();objectobj=bf.Deserialize(ms);DataSetds=(DataSet)obj;returnds;}catch(Exceptionex){errorinfo=ex.ToString();returnnull;}}
解决方案三:
DATASET要求不能序列化,并且用内存流也不行吧,因为在俩个不同的机子上也,麻烦你在想想
解决方案四:
帮你顶上去,一定不能让它沉下去。同时关注此问题......
解决方案五:
google上直接搜索IMessageSink和Remoting,有很多文章说的