WCF ria服务SP1超时已过期

时间:2011-07-25 05:00:13

标签: entity-framework-4 timeout wcf-ria-services

我的解决方案是Silverlight,它使用WCF RIA服务SP1和实体框架4。

我在加载大尺寸数据时遇到问题。

我收到此错误消息。

  

System.ServiceModel.DomainServices.Client.DomainException:超时已过期。操作完成之前经过的超时时间或服务器没有响应。

我认为这是一个关于超时的问题,所以我尝试了下面的代码。当我没有安装WCF Ria服务“SP1”时它工作。 但是因为我已经安装了“SP1”而无法正常工作。

ChannelFactory<BatchContext.IBatchServiceContract> channel = ((WebDomainClient<BatchContext.IBatchServiceContract>)this.DomainClient).ChannelFactory;
channel.Endpoint.Binding.OpenTimeout = new TimeSpan(0, 30, 0);  
channel.Endpoint.Binding.CloseTimeout = new TimeSpan(0, 30, 0);    
channel.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 30, 0);    
channel.Endpoint.Binding.SendTimeout = new TimeSpan(0, 30, 0);

我该怎么办?

1 个答案:

答案 0 :(得分:1)

我将解释我的背景,并希望它对我的工作有用。我很确定。

首先在我的例子中调用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); 

    }
}

我期待着您的反馈。

相关问题