【问题标题】:how can we handle this situvation in wcf [closed]我们如何在 wcf 中处理这种情况 [关闭]
【发布时间】:2012-01-04 11:03:00
【问题描述】:

任何机构都可以帮助我处理

  1. 我的 WCF 服务工作正常
    wcf 具有具有 100 条记录的数据库连接数据库
    WCF 服务从数据库中获取记录,当客户端请求记录时,这些记录必须提交给客户端系统。
  2. 当客户端请求记录时,它可以正常处理 10-20 条记录,但由于客户端和 WCF 服务之间的巨大流量,服务不提供服务,它会获取 100 条记录。

我们如何在 WCF 中处理这种情况?

【问题讨论】:

  • 你有什么错误吗???
  • 客户端无法处理 100 条记录,但 10-20 条记录工作正常

标签: wcf wcf-ria-services


【解决方案1】:

如果它抛出消息大小太大的异常,您可以查看此问题中列出的一些选项:Setting Max Message and buffer size for WCF webhttp

您的服务最多返回 100 条记录吗?如果它只会增长和增长,我不建议更改消息大小。相反,您可能应该考虑某种分页机制,所以如果您有一个看起来像这样的方法:

IEnumerable<Record> GetRecords()

制作:

Response GetRecords(index)

那么响应应该是这样的:

[DataContract]
public class Response
{
    [DataMember]
    IEnumerable<Record> Records { get; set; }

    [DataMember}
    bool IsLast { get; set; }

    [DataMember]
    int PageIndex { get; set }
}

然后你会像这样从客户端调用它:

Response resp;
int pageIndex = 0;
do
{
    resp = service.GetRecords(pageIndex);
    // use resp.Records here - could just build a bigger list with them all in
    // and use it after the loop or if your client can handle chunks, just use it
    pageIndex = resp.PageIndex + 1;
} while(!resp.IsLast);

不是最复杂的分页,但它为您提供了一个充满希望的地方。

【讨论】:

    猜你喜欢
    • 2020-04-15
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多