【问题标题】:Silverlight 4 WCF RIA Service Timeout ProblemSilverlight 4 WCF RIA 服务超时问题
【发布时间】:2010-11-11 00:41:18
【问题描述】:

我有一个 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 行为)

为什么会这样?

【问题讨论】:

    标签: silverlight silverlight-4.0 wcf


    【解决方案1】:

    我在这里回答了同样的问题: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来改变创建的域上下文的行为。在这堂课中,你应该写:

    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. 您尚未将 DomainService 配置为序列化足够多的对象。默认值非常小。试试this tip我昨天放的增加结果集分配
      2. 您的数据源可能会超时。在这种情况下,您需要相应地增加 LINQ to SQL、EF 或 ADO.NET 的命令超时。这是不太可能的原因,但需要考虑。

      【讨论】:

        猜你喜欢
        • 2011-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-14
        • 2013-05-12
        • 1970-01-01
        相关资源
        最近更新 更多