When writing a web service, you must consider the transmission speed. You must compress and transfer large data files or images, and decompress them on the client to reduce the transmission time!
Below are the main Code : 1 // Server:
2 [Webmethod]
3 Public Byte [] Search ( String ID)
4 {
5 // Compression
6 Memorystream ostream = New Memorystream ();
7 Deflatestream zipstream = New Deflatestream (ostream, compressionmode. Compress );
8 Zipstream. Write (bytes, 0 , Bytes. Length );
9 Zipstream. Flush ();
10 Zipstream. Close ();
11 Return Ostream. toarray ();
12 }
13
14 // Client:
15 Public Dataset decompressiondataset ( Byte [] Bytes)
16 {
17 // Initialize the stream and set the read location
18 Memorystream mstream = New Memorystream (bytes );
19 Mstream. Seek ( 0 , Seekorigin. Begin );
20 // Extract
21 Deflatestream unzipstream = New Deflatestream (mstream, compressionmode. decompress, True );
22 // Deserialization to obtain a dataset
23 Dataset dsresult = New Dataset ();
24 Dsresult. remotingformat = Serializationformat. Binary;
25 Binaryformatter bformatter = New Binaryformatter ();
26 Dsresult = (Dataset) bformatter. deserialize (unzipstream );
27 Return Dsresult;
28 }