2011-02-02 121 views
0

我正在從我的Silverlight客戶端調用我的DomainService,通常需要2分鐘。我需要將端點的超時值延長到5分鐘才能安全,但似乎忽略了該設置,我找不到原因。這裏是我如何在我的客戶創造我DomainContext:Silverlight 4 Ria服務超時問題

MyDomainContext context = new MyDomainContext(); 
((WebDomainClient<MyDomainContext.IMyDomainServiceContract>)context.DomainClient).ChannelFactory.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 5, 0); 
context.Search(_myParms, p => 
    { 
     if (p.HasError) 
     { 
     // Handle errors 
     } 

     // Should take about 2 min. to get here, but times out before   
    }, null); 

我已經嘗試設置ReveiveTimeout和雙方的SendTimeout,但我總是在完全相同1分鐘得到錯誤。

有人能告訴我我做錯了什麼嗎?

編輯:這是我得到確切的錯誤:

{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass2.b_0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

我還測試,以確保它不是在我的服務。目前,我只是讓我的服務運行一段時間。再一次,我正好在一分鐘內得到這個錯誤。

感謝,

斯科特

回答

2

你應該實現分部方法MyDomainContex類的OnCreated()。

樣品:

public partial class TestDomainContext 
{ 
    partial void OnCreated() 
    { 
     var proxy = (WebDomainClient<Test.Server.Services.TestDomainContext.ITestDomainServiceContract>)this.DomainClient; 
     proxy.ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0); 
    } 
+0

不幸的是,這並沒有奏效。在一分鐘之後,我仍然會收到同樣的錯誤。我已更新我的原始帖子,以顯示我正在收到的確切錯誤。 – Scott 2011-02-02 19:02:01

0

難道是在承載域服務的服務器端Web應用程序的請求超時?檢查運行服務的Web應用程序或應用程序池的設置。

+0

我的DomainServices目前正在Visual Studio的內部Web服務器中託管。有沒有辦法改變VS中的超時值?這可能是問題... – Scott 2011-02-02 19:55:22

1

這個問題是Silverlight中的一個難點。

我更喜歡這樣的東西的擴展方法,而不是創建微妙的部分類。如果您使用棱鏡 http://blogs.msdn.com/b/kylemc/archive/2010/11/03/how-to-change-the-request-timeout-for-wcf-ria-services.aspx

你可以注入如下:

見這裏的解決方案

_unityContainer.RegisterType<SurveyModuleContext>(new InjectionFactory(c => CreateSurveyContext())); 



    private object CreateSurveyContext() 
    { 
     var context = new SurveyModuleContext(); 
     context.ChangeWcfSendTimeout(new TimeSpan(0, 10, 0)); 
     return context; 
    } 


public static class DomainContextExtensions 
{ 
    public static void ChangeWcfSendTimeout(this DomainContext context, 
              TimeSpan sendTimeout) 
    { 
     PropertyInfo channelFactoryProperty = 
      context.DomainClient.GetType().GetProperty("ChannelFactory"); 
     if (channelFactoryProperty == null) 
     { 
      throw new InvalidOperationException(
       "There is no 'ChannelFactory' property on the DomainClient."); 
     } 

     ChannelFactory factory = (ChannelFactory)channelFactoryProperty.GetValue(context.DomainClient, null); 
     factory.Endpoint.Binding.SendTimeout = sendTimeout; 
    } 
} 

您可以在這張截圖,該解決方案確實看到工作。 (2m 1s)電話

using firebug network request and response 2m 1s.