代码之家  ›  专栏  ›  技术社区  ›  Daniel Coffman

Silverlight 4 WCF RIA服务超时问题

  •  2
  • Daniel Coffman  · 技术社区  · 14 年前

    我有一个silverlight 4用户控件,它调用一个运行很长的wcf ria服务。如下图所示,我正在增加默认超时时间。

    _domainContext = new WindowsDashboardDomainContext();
    // Increase timeout -- this can be a very long running query
    ((WebDomainClient<WindowsDashboardDomainContext.IWindowsDashboardDomainServiceContract>)
    _domainContext.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(99, 0, 0);
        _domainContext.GetSections( "All", "All", "All" ).Completed += GetAllSectionsCompleted;
    

    不幸的是,它似乎忽略了此超时,仍然抛出超时异常:

    错误:查询“getclicks”的Silverlight应用程序加载操作失败,出现未处理的错误。执行命令定义时出错。有关详细信息,请参见内部异常。内部异常消息:超时已过期。在操作完成之前经过的超时时间或服务器没有响应。在system.data.entityclient.entitycommanddefinition.executestorecommands(entitycommand entitycommand,commandbehavior行为)

    为什么会这样?

    2 回复  |  直到 13 年前
        1
  •  2
  •   Community c0D3l0g1c    7 年前

    我在这里回答了同样的问题: WCF ria service SP1 timeout expired

    答案是:

    我会解释我的背景,我希望它能为我的工作。我确信。

    首先调用ria服务,并使用一些域上下文,在我的示例中:

    EmployeeDomainContext context = new EmployeeDomainContext();
    InvokeOperation<bool> invokeOperation = context.GenerateTMEAccessByEmployee(1, 'Bob');
    invokeOperation.Completed += (s, x) =>
        {....};
    

    在这之前没什么新鲜事。有了这个,我每次都会在1分钟后遇到同样的超时异常。我花了很多时间试图面对如何更改超时定义,我尝试了web.config中所有可能的更改,但什么都没有。解决办法是:

    创建customemployeedomaincontext,这是一个部分类 定位在生成代码的同一路径中 这个类使用oncreate的hook方法来更改创建的域上下文的行为。在这门课上你应该写:

    public partial class EmployeeDomainContext : DomainContext
    {
        partial void OnCreated()
        {
            PropertyInfo channelFactoryProperty = this.DomainClient.GetType().GetProperty("ChannelFactory");
            if (channelFactoryProperty == null)
            {
                throw new InvalidOperationException(
                  "There is no 'ChannelFactory' property on the DomainClient.");
            }
    
            ChannelFactory factory = (ChannelFactory)channelFactoryProperty.GetValue(this.DomainClient, null);
    
            factory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 10, 0); 
    
        }
    }
    

    我期待你的反馈。

        2
  •  1
  •   Community c0D3l0g1c    7 年前

    我想到了两种可能性:

    1. 您没有将域服务配置为序列化足够的对象。默认值非常小。试用 this tip 我昨天提出增加结果集分配
    2. 数据源可能超时。在这种情况下,需要相应地增加linq to sql、ef或ado.net的命令超时。这是不太可能的原因,但需要考虑。