Silverlight 4 WCF RIA 服务超时问题 [英] Silverlight 4 WCF RIA Service Timeout Problem

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

问题描述

我有一个 Silverlight 4 用户控件,它调用一个运行时间很长的 WCF RIA 服务.如下所示,我正在增加默认超时时间.

I have a Silverlight 4 usercontrol that calls a very long running WCF RIA service. As shown below, I am increasing the default timeout period.

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

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

Unfortunately, it seems to ignore this timeout and still throws the timeout exception:

错误:Silverlight 应用程序加载操作中未处理的错误对于查询GetClicks"失败.执行命令定义时发生错误.有关详细信息,请参阅内部异常.内部异常消息:超时已过期.操作完成前超时时间已过或服务器未响应.在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior 行为)

Error: Unhandled Error in Silverlight Application Load operation failed for query 'GetClicks'. An error occurred while executing the command definition. See the inner exception for details. Inner exception message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

为什么会这样?

推荐答案

我在这里回答了同样的问题:WCF ria 服务 SP1 超时已过期

I answered the same question here: WCF ria service SP1 timeout expired

答案:

我会解释我的背景,我希望它对我有用.我确信这一点.

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

    }
}

期待您的反馈.

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

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