我正在处理复杂的 .NET 客户端服务器体系结构定制,我绝对无法控制发送或接收的请求/回复,除非我可以将我的东西添加到请求/回复对象中。
我在服务器端有一个数据集要发送到客户端,我正在使用 GZipStream 压缩数据集。压缩工作正常,但是当在客户端收到回复时,我得到无效字符异常 - 0x1F。我用谷歌搜索,找不到合适的资源来解决这个问题。
压缩代码:
Private Function Compress(ByVal data() As Byte) As Byte()
Try
'---the ms is used for storing the compressed data---
Dim ms As New MemoryStream()
Dim zipStream As Stream = Nothing
zipStream = New GZipStream(ms, _
CompressionMode.Compress, True)
'---or---
'zipStream = New DeflateStream(ms, _
' CompressionMode.Compress, True)
'---compressing using the info stored in data---
zipStream.Write(data, 0, data.Length)
zipStream.Close()
ms.Position = 0
'---used to store the compressed data (byte array)---
Dim compressed_data(CInt(ms.Length - 1)) As Byte
'---read the content of the memory stream into
' the byte array---
ms.Read(compressed_data, 0, CInt(ms.Length))
Return compressed_data
Catch ex As Exception
Return Nothing
End Try
End Function
考虑到我可以更改请求/响应处理机制这一事实,任何解决此问题的想法都非常感谢。此外,我还请求有关通过 Web 服务处理大型数据集传输的更好方法的任何想法。谢谢你。