实体框架数据压缩

发布于 2025-01-02 03:20:42 字数 428 浏览 2 评论 0原文

我有一个 WCF Windows 服务,它通过压缩数据集向 250 多个 PDA 提供数据,并且希望重新开发该服务和移动应用程序以使用 Entity Framework 4.x 模型。

为了在 PDA 上发送/接收数据时保持可接受的性能,我需要保持数据大小尽可能小,并且想知道是否可以从 WCF windows 服务压缩 IEnumerable?

根据之前使用数据集的经验,我获得了 80%+/- 的压缩率,甚至在 PDA 上解压缩数据也获得了 50% 的总体性能提升,因此保持类似的性能水平至关重要。

编辑: 我可以使用二进制序列化器然后压缩流吗? 如图所示

I have a WCF Windows service that provides data to 250+ PDAs via compressed datasets and was looking to redevelop both the service and the mobile application to use Entity Framework 4.x models.

In order to keep performance acceptable when sending/receiving data on the PDA I need to keep the data size as small as possible and was wondering if its possible to compress a IEnumerable from the WCF windows service?

From previous experience with the datasets I got a 80%+/- compression rate and even decompressing the data on the PDA achieved an overal 50% performance importment so retaining similar levels of performance is critical.

EDIT:
Could I use a binary serializer and then compress the stream? As shown here

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭⌒浅淡时光〆 2025-01-09 03:20:42

如果您无法使用内置的 IIS GZip 功能,那么您始终可以手动执行此操作,例如

public static byte[] Compress(this IEnumerable<T> list)
{
    using (var stream = new MemoryStream())
    {
        using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
        {
            var formatter = new BinaryFormatter();
            formatter.Serialize(zip, list);
        }
        return stream.ToArray();
    } 
}

,然后只需让您的 WCF 方法返回一个字节数组,然后您就可以解压缩该字节数组。在客户端反序列化。

上面的代码是一个扩展方法,因此您基本上只需调用 return myList.compress() 即可。

If you can't use the built in IIS GZip capabilities then you can always do it manually e.g.

public static byte[] Compress(this IEnumerable<T> list)
{
    using (var stream = new MemoryStream())
    {
        using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
        {
            var formatter = new BinaryFormatter();
            formatter.Serialize(zip, list);
        }
        return stream.ToArray();
    } 
}

Then just have your WCF method return a byte array which you can then decompress & deserialize on the client side.

The above code is an extension method so you can basically just call return myList.Compress().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文