How does web service transmit big data files?

Source: Internet
Author: User
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 }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.