Silverlight分页webservice结果

时间:2014-06-10 13:59:03

标签: web-services silverlight

我们有一个Silverlight应用程序,它调用Web服务从SQL Server检索数据库行。然后将它们显示在屏幕上的分页控件中。但是,需要整个表,它包含数千行。在客户系统上,如果我们要求超过1500行,我们会得到HttpRequestTimedOutWithoutDetail。在我们的开发系统中,在此之前我们需要大约500,000行。

显然,我们应该做的是分页结果并将它们一点一点地返回到silverlight。但我不知道该怎么做。任何人都可以建议,或指向一些明确解释原则和方法的网页(我有点简单!)

以下是Web服务中的代码:

    public IQueryable<Referral> GetReferrals()
    {
        /*
         * In the customer's environments it seems that any more than around 1500 referrals will break the system: they will fail to load.
         * In the dev environment is takes around 500,000 so it seems to be timeout related.
         * 
         * The code below was an attempt to restrict the number, only returning referrals above a certain size and within a certain age.
         * It seems the customer is more interested in the smaller referrals though since they are more likely to be added to existing
         * substations so if this method is re-instated, we should be using '<' instead of '>'
         * 
        int mdToBeMet = int.Parse(ConfigurationManager.AppSettings["ReferralMDToBeMet"]);
        DateTime minusNYears = DateTime.Today.AddYears(int.Parse(ConfigurationManager.AppSettings["ReferralTargetDate"]) * -1);
        int maxReferralsCount = int.Parse(ConfigurationManager.AppSettings["ReferralMaxRecordCount"]);
        if (mdToBeMet != 0 && maxReferralsCount != 0)
        {
            return this.ObjectContext.Referrals.Where(x => x.MD_to_be_Met > mdToBeMet && x.Target_Date > minusNYears).OrderByDescending(y => y.Target_Date).Take(maxReferralsCount);
        }
        */

        /*
         * This is the 2nd attempt: the customer is mainly interested in referrals that have an allocated substation
         */
        bool allocatedReferralsOnly = bool.Parse(ConfigurationManager.AppSettings["ReferralAllocatedOnly"]);
        int maxReferralsCount = int.Parse(ConfigurationManager.AppSettings["ReferralMaxRecordCount"]);

        if (allocatedReferralsOnly)
        {
            var referrals = this.ObjectContext.Referrals.Where(x => x.Sub_no != "").OrderByDescending(y => y.Target_Date).Take(maxReferralsCount);
            return referrals;
        }
        else
        {

            /*
             * Ideally, we should just page the referrals here and return to retrieving all of them, bit by bit.
             */
            var referrals = this.ObjectContext.Referrals;
            return referrals;
        }
    }

非常感谢任何建议。

1 个答案:

答案 0 :(得分:0)

扩展我给出的评论的一个例子......

/// <summary>
/// Returns a page of Referrels
/// pageNumber is 0-index based
/// </summary>
public IQueryable<Referrel> GetReferrals(int pageNumber)
{
    var pageSize = 100;
    return ObjectContext.Referrals.Skip(pageNumber*pageSize).Take(pageSize);
}

显然,如果你愿意,也可以传入pageSize,或者在此方法之外的某个地方将其定义为常量。