Configuring a Timeout to Call the WCF RIA Service from a Silverlight 3 Client

I am using WCF RIA Services Beta with Silverlight 3.0, and I want to be able to set a timeout from the client. I know that the underlying technology is WCF, and the default timeout is 60 seconds, as I expected.

Is there an easy way to manage this and other WCF settings?

My first thought is to try DomainContext OnCreated , which was mentioned in RIA Services Overview , which was available before RIA Services went into beta. The MSDN documentation for the DomainContext object no longer mentions the method, although it still exists? I am not sure if this is a case of documentation lagging or an indication that I should not use this extensibility point.

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

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

Or one line after creating the domain context:

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

or partial class

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);
   }
}
+3

, , Silverlight. , . , WebDomainClient, Binding private WebDomainClient(Uri serviceUri, bool usesHttps, Binding binding), XML Comment . , 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);
    }
}
+1

Source: https://habr.com/ru/post/1731954/


All Articles