使用 Delphi 压缩列表数据 C# Web 服务发送到独立客户端

发布于 2025-01-04 02:58:55 字数 1870 浏览 1 评论 0原文

我有一个 .Net WebService 和一个用 DelphiXE2 编写的独立应用程序。

当我提交包含大量项目 (400) 的列表时,FindAllEntity() 方法非常慢。

我研究了压缩列表的数据部分,但我只找到了 Gzip C#,它用于压缩文件和图像。

有没有办法压缩可以快速发送到独立应用程序的数据列表?

这是代码:

//MyRegularNewEntity
    public class _MyEntity
    {
        public decimal id { get; set; }
        public _otherEntity Customers { get; set; }
        public string serial { get; set; }
        public decimal cost { get; set; }
    }

    //My Controller
    public IQueryable<c#ModelEntity> GetAllDatOfEntity()
    {

        IQueryable<C#ModelEntity> Dat;
        //The containt of data base entity is save in Dat ListQueryable
        Dat = db.MyEntity;

        return Dat;           
    }

    //My WebService
    [WebMethod]
    public List<_MyRegularEntity> FindAllEntity()
    {
        //Construct my repository
        MyRepository ag = new MyRepository();
        //Asign the result in a variable of call to get all the dat
        var Dat = ag. GetAllDatOfEntity();
        //Contruct the List with my entity to send for my client
        List<_MyRegularEntity> list = new List<_MyRegularEntity>();
        //Add all dat element to my list
        if (Dat != null)
        {
            foreach (var item in Dat)
            {
               var MyEntity = new _MyRegularEntity();
               MyEntity.id = item.id,
               MyEntity.Custormers = new _otherEntity()
               {
                   id=item.Customers.id,
                   firstname=item.Customers.firstname,
                   lastname=item.Custormers,lastname
               },
               MyEntity.Serial = item.Serial,
               MyEntity.Cost = item.Cost

               list.Add(MyEntity);
            };

         }
        //THIS IS THE RESULT I NEED COMPRESS
        return list;
    }

I have a .Net WebService and a standalone application written in DelphiXE2.

When I submit a list with lots of items (400) the FindAllEntity() method is very slow.

I researched compressing the data components of a list, but I only found Gzip C#, which is used for compressing files and image.

Is there a way to compress a list of data that can be sent quickly to the standalone application?

Here's the code:

//MyRegularNewEntity
    public class _MyEntity
    {
        public decimal id { get; set; }
        public _otherEntity Customers { get; set; }
        public string serial { get; set; }
        public decimal cost { get; set; }
    }

    //My Controller
    public IQueryable<c#ModelEntity> GetAllDatOfEntity()
    {

        IQueryable<C#ModelEntity> Dat;
        //The containt of data base entity is save in Dat ListQueryable
        Dat = db.MyEntity;

        return Dat;           
    }

    //My WebService
    [WebMethod]
    public List<_MyRegularEntity> FindAllEntity()
    {
        //Construct my repository
        MyRepository ag = new MyRepository();
        //Asign the result in a variable of call to get all the dat
        var Dat = ag. GetAllDatOfEntity();
        //Contruct the List with my entity to send for my client
        List<_MyRegularEntity> list = new List<_MyRegularEntity>();
        //Add all dat element to my list
        if (Dat != null)
        {
            foreach (var item in Dat)
            {
               var MyEntity = new _MyRegularEntity();
               MyEntity.id = item.id,
               MyEntity.Custormers = new _otherEntity()
               {
                   id=item.Customers.id,
                   firstname=item.Customers.firstname,
                   lastname=item.Custormers,lastname
               },
               MyEntity.Serial = item.Serial,
               MyEntity.Cost = item.Cost

               list.Add(MyEntity);
            };

         }
        //THIS IS THE RESULT I NEED COMPRESS
        return list;
    }

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

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

发布评论

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

评论(1

书间行客 2025-01-11 02:58:55

Gzip 压缩可以在 IIS 中的服务器级别启用或通过 web.config 文件启用。它不仅用于传输“文件”,还用于在客户端和服务器之间传输任何内容。

但是,您应该分析 Web 服务,看看是否确实是数据传输缓慢,或者 FindAllEntity() 方法内部是否存在其他原因导致速度缓慢。

Gzip compression can be turned on at the server level in IIS or through your web.config file. It is used not just for transferring "files" but really for transferring anything between the client and server.

However, you should profile the web service to see if it's actually the transferring of data that is slow or if there is something else inside of your FindAllEntity() method that is slow.

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