.NET Web 服务上的 GZipStream 导致无效字符问题

发布于 2024-12-08 16:06:40 字数 1355 浏览 0 评论 0原文

我正在开发复杂的 .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 服务处理大型数据集传输的更好方法的任何想法。谢谢。

I'm working on a complex .NET client server architecture customization and I absolutely have no control over request/reply sent or received except that I can add my stuff to the request/reply objects.

I've a dataset on server side to be sent to client andI'm using GZipStream to compress the dataset. The compression works fine, but when the reply is received on client end, I get invalid character exception - 0x1F. I googled and could not find appropriate resource to address this issue.

Compression code:

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

Any idea to fix this issue considering the fact that I can alter the request/response handling mechanism is really appreciated. In addition, I also request any ideas on better ways handling large dataset transfers over webservice. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文