WCF ria service SP1 timeout expired

怎甘沉沦 提交于 2019-12-19 10:15:49

问题


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

I have a problem with loading large size data.

I've got this error message.

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

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

What should I do?


回答1:


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

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) =>
    {....};

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:

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

    }
}

I looking forward for you feedback.



来源:https://stackoverflow.com/questions/6811944/wcf-ria-service-sp1-timeout-expired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!