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

时间:2012-02-10 21:28:33

标签: list c#-4.0 compression asmx delphi-xe2

我有一个.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;
    }

1 个答案:

答案 0 :(得分:0)

Gzip压缩可以是turned on at the server level in IIS或通过您的web.config文件。它不仅用于传输“文件”,还用于在客户端和服务器之间传输任何内容。

但是,您应该对Web服务进行概要分析,以查看它实际上是否传输数据的速度很慢,或者FindAllEntity()方法中的其他内容是否很慢。