配置来自Silverlight 3客户端的WCF RIA服务调用的超时

配置来自Silverlight 3客户端的WCF RIA服务调用的超时,wcf,silverlight,wcf-ria-services,Wcf,Silverlight,Wcf Ria Services,我使用的是Silverlight 3.0,我希望能够从客户端配置超时。我知道底层技术是WCF,默认超时时间似乎是60秒 是否有一种简单的方法来控制此设置和其他WCF设置 我的第一个想法是尝试OnCreated钩子点,该钩子点在RIA服务概述pdf文件中提到,该文件在RIA服务进入测试版之前可用。对象的MSDN文档不再提及该方法,尽管它仍然存在?我不确定这是文档落后的情况还是我不应该使用这个扩展点的迹象 namespace Example.UI.Web.Services { public

我使用的是Silverlight 3.0,我希望能够从客户端配置超时。我知道底层技术是WCF,默认超时时间似乎是60秒

是否有一种简单的方法来控制此设置和其他WCF设置

我的第一个想法是尝试OnCreated钩子点,该钩子点在RIA服务概述pdf文件中提到,该文件在RIA服务进入测试版之前可用。对象的MSDN文档不再提及该方法,尽管它仍然存在?我不确定这是文档落后的情况还是我不应该使用这个扩展点的迹象

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

作为参考,下面的代码几乎可以工作,但您无法使用Silverlight中的反射访问私有成员。无论如何,我都不会对这种黑客行为感到高兴。有趣的是,有一个WebDomainClient构造函数接受绑定参数
私有WebDomainClient(Uri serviceUri,bool useshtps,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);
    }
}
公共密封部分类AppDomainContext
{
部分void OnCreated()
{
var webDomainClient=((webDomainClient)this.DomainClient);
//我可以在这里使用反射来获得绑定吗
var bindingField=webDomainClient.GetType().GetField(“_binding”,BindingFlags.NonPublic | BindingFlags.Instance);
//在Silverlight中,无法使用反射访问私有字段的值,因此GetValue调用引发异常
// http://msdn.microsoft.com/en-us/library/4ek9c21e%28VS.95%29.aspx
var binding=bindingField.GetValue(webDomainClient)作为System.ServiceModel.Channels.binding;
//那么近,那么远!!
binding.SendTimeout=新的时间跨度(0,0,1);
}
}

域上下文创建后的任一行:

((WebDomainClient<LibraryDomainContext.ILibraryDomainServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
((WebDomainClient)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);
   }
}
公共部分类LibraryDomainContext
{
部分void OnCreated()
{
if(DesignerProperties.GetIsInDesignMode(App.Current.RootVisual))
((WebDomainClient)this.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout=new TimeSpan(0,5,0);
}
}

我不再使用此代码库,但很高兴知道他们最终公开了此代码。我当时正在使用测试版。顺便说一句,这不适用于RTM,或者至少我不知道如何使用。下面是使用silverlight 4的更新:我们如何通过web.config配置它?