WCF ria服务SP1超时已过期 [英] WCF ria service SP1 timeout expired

查看:135
本文介绍了WCF ria服务SP1超时已过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My solution is Silverlight which uses WCF RIA service SP1 and Entity Framework 4.

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

I have a problem with loading large size data.

我有这个错误消息。


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

System.ServiceModel.DomainServices.Client.DomainException : Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

我认为这是超时的问题,所以我尝试下面的代码。当我没有安装WCF Ria服务SP1时它工作。
但是,由于我安装了SP1,它不起作用。

I think that it's a problem regards with timeout, so I tried below code. It worked when I hadn't install WCF Ria service "SP1". But it's not working since I've installed "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);

我该怎么办?

推荐答案

我将解释我的上下文,我希望它能为我工作。我确定这个。

I'll explain my context and I wish it will work for my. I'm sure about that.

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

First of all to call RIA services, and using some domain context, in my example:

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

直到这里都没有新内容。而且,我每次在1分钟后面临相同的超时异常。我花了很多时间尝试面对如何更改超时定义,我尝试了所有可能的更改在Web.config和没有。解决方案是:

Nothing new until here. And with this I was facing every time that same timeout exception after 1 minute. I spend quite a lot of time trying to face how to change the timeout definition, I tried all possible changes in Web.config and nothing. The solution was:

创建一个CustomEmployeeDomainContext,这是在生成的代码的同一路径中本地化的局部类,此类使用钩子方法OnCreate来更改创建的域上下文的行为。在这个类中,你应该写:

Create a CustomEmployeeDomainContext, that is a partial class localizated in the same path of the generated code and this class use the hook method OnCreate to change the behavior of created domain context. In this class you should wrote:

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); 

    }
}

我期待您的反馈。

这篇关于WCF ria服务SP1超时已过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆