Using soap to transmit data over the network results in a slow transmission speed due to a large amount of data. To solve this problem, you can zip the file before passing it. Because almost all data is transmitted in the database, the compression space is very large. Tested, it can be compressed to the original 1/15 Method 1: use Java CompressionAlgorithm. Because the DLL is directly provided by. net. Reference vjslib. dll ------------------------ Code ----------------------- Using system; Using java. IO; Using java.util.zip; Using COM. Ms. vjsharp. @ struct; Namespace soapgrid { /// <Summary> /// Zip summary. /// </Summary> Public class zip { Public static sbyte [] compressstring (string S) { Deflater F = new Deflater (Deflater. best_compression ); Sbyte [] DATA = javastructmarshalhelper. converttobytearray (s ); F. setinput (data ); F. Finish (); Bytearrayoutputstream o = new bytearrayoutputstream (data. Length ); Try { Sbyte [] Buf = new sbyte [1024]; While (! F. Finished ()) { Int got = f. Deflate (BUF ); O. Write (BUF, 0, got ); } } Finally { O. Close (); } Return O. tobytearray (); } Public static string decompressstring (sbyte [] S) { Inflater F = new Inflater (); F. setinput (s ); Bytearrayoutputstream o = new bytearrayoutputstream (S. Length ); Try { Sbyte [] Buf = new sbyte [1024]; While (! F. Finished ()) { Int got = f. Inflate (BUF ); O. Write (BUF, 0, got ); } } Finally { O. Close (); } Return javastructmarshalhelper. converttostring (O. tobytearray ()); } } } ---------------------------------- End code ------------------------- However, an error may occur when the data volume is large (more than 2 MB. The reason may be that the data types of Java and C # are not completely uniform. For example, the conversion between byte and sbyte may cause problems. Method 2: Use sharpziplib. Open source and C # development. You need to download the DLL of sharpziplib, or download the source code and compile it yourself. He provides examples (mostly about file operations) ---------------------------------- Code --------------------- Using system; Using system. IO; Using icsharpcode. sharpziplib. Zip. compression; Using icsharpcode. sharpziplib. Zip. Compression. streams; Using icsharpcode. sharpziplib. Zip; Using icsharpcode. sharpziplib. Bzip2; Namespace soapgrid { /// <Summary> /// Summary of cszip. /// </Summary> Public class cszip { Public static byte [] compressbytes (byte [] data) { Deflater F = new Deflater (Deflater. best_compression ); F. setinput (data ); F. Finish (); Memorystream o = new memorystream (data. Length ); Try { Byte [] Buf = new byte [1, 1024]; While (! F. isfinished) { Int got = f. Deflate (BUF ); O. Write (BUF, 0, got ); } } Finally { O. Close (); } Return O. toarray (); } Public static byte [] decompressbytes (byte [] data) { Inflater F = new Inflater (); F. setinput (data );
Memorystream o = new memorystream (data. Length ); Try { Byte [] Buf = new byte [1, 1024]; While (! F. isfinished) { Int got = f. Inflate (BUF ); O. Write (BUF, 0, got ); } } Finally { O. Close (); } Return O. toarray (); } } } --------------------------------- End code ----------------------- After testing, there is no problem with large data volumes. The test shows that the compression ratio reaches 22 times. |