2009-12-16 32 views
2

我在Silverlight 3.0中使用WCF RIA Services Beta,我希望能夠從客戶端配置超時。我知道底層技術是WCF,默認的超時時間似乎是60秒,正如我所預料的那樣。從Silverlight 3客戶端配置WCF RIA Services調用的超時時間

有沒有簡單的方法來控制這個和其他WCF設置?

我首先想到的是去嘗試這是在爲RIA服務之前,可準備公測RIA服務概述 PDF文件中提到的DomainContextOnCreated掛鉤點。 DomainContext對象的MSDN文檔不再提及該方法,儘管它仍然存在?我不確定這是否是文檔滯後的情況,或者是否表明我不應該使用此擴展點。

namespace Example.UI.Web.Services 
{ 
    public sealed partial class CustomDomainContext 
    { 
     partial void OnCreated() 
     { 
      // Try and get hold of the WCF config from here 
     } 
    } 
} 

回答

3

http://blogs.objectsharp.com/CS/blogs/dan/archive/2010/03/22/changing-timeouts-in-wcf-ria-services-rc.aspx

任一行:

((WebDomainClient<LibraryDomainContext.ILibraryDomainServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0); 

或部分類

public partial class LibraryDomainContext 
{ 
    partial void OnCreated() 
    { 
     if(DesignerProperties.GetIsInDesignMode(App.Current.RootVisual)) 
     ((WebDomainClient<LibraryDomainContext.ILibraryDomainServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0); 
    } 
} 
+0

我不再在這個代碼庫上工作,但很高興知道他們最終揭露了這一點。我當時正在使用Beta版。 – 2010-07-04 22:34:38

+0

順便說一句這不適用於RTM,或者至少我不知道如何。 – 2010-11-03 19:33:23

+1

以下是使用silverlight 4的更新:http://blogs.msdn.com/b/kylemc/archive/2010/11/03/how-to-change-the-request-timeout-for-wcf-ria- services.aspx – Jonx 2010-11-24 14:00:21

1

僅供參考下面作品的代碼,但你不能在Silverlight中使用反射訪問私有成員。儘管如此,對這個黑客不會感到滿意。有趣的是,有一個WebDomainClient構造函數需要一個綁定參數private WebDomainClient(Uri serviceUri, bool usesHttps, Binding binding),但是這個狀態的XML註釋私有構造函數。一旦我們在WCF之上有一個端到端的可擴展性故事,就應該公開。看起來我必須等待一段時間才能將這種配置公開給我們。域上下文創建後

public sealed partial class AppDomainContext 
{ 
    partial void OnCreated() 
    { 
     var webDomainClient = ((WebDomainClient<AppDomainContext.IAppDomainServiceContract>)this.DomainClient); 
     // Can I use reflection here to get hold of the Binding 
     var bindingField = webDomainClient.GetType().GetField("_binding", BindingFlags.NonPublic | BindingFlags.Instance); 

     // In Silverlight, the value of a private field cannot be access by using reflection so the GetValue call throws an exception 
     // http://msdn.microsoft.com/en-us/library/4ek9c21e%28VS.95%29.aspx 
     var binding = bindingField.GetValue(webDomainClient) as System.ServiceModel.Channels.Binding; 

     // So near yet so far!! 
     binding.SendTimeout = new TimeSpan(0,0,1); 
    } 
} 
+0

我們如何能夠通過的web.config配置呢? – 2012-09-13 12:30:39

相關問題