2011-07-25 74 views
2

我的解決方案的Silverlight它使用WCF RIA服務SP1和Entity Framework 4WCF RIA服務SP1超時過期

我有裝載大尺寸的數據有問題。

我有這個錯誤信息。

System.ServiceModel.DomainServices.Client.DomainException:Timeout過期。操作完成之前超時的時間或服務器沒有響應。

我認爲這是一個問題關於超時,所以我嘗試了下面的代碼。它工作時,我沒有安裝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

我會解釋我的情況,我希望它能爲我的工作。我很確定。

首先調用RIA服務,並使用一些領域的背景下,我的例子:

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

沒有新東西,直到這裏。與此同時,我每次在1分鐘後都面臨同樣的超時異常。我花了很多時間試圖去面對如何改變超時定義,我嘗試了Web.config中的所有可能的改變,而沒有做任何改變。解決的辦法是:

創建CustomEmployeeDomainContext,即在生成的代碼的相同路徑localizated的局部類和此類中使用的鉤方法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); 

    } 
} 

我期待您的反饋。