views:

1878

answers:

3

I'm using the WCF RIA Services Beta with Silverlight 3.0 and I want to be able to configure the timeout from the client. I know that the underlying technology is WCF and the default timeout seems to be 60 seconds as I would expect.

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

My first thought is to try the DomainContext OnCreated hook point which was mentioned in the RIA Services Overview pdf file that was available prior to RIA Services going beta. The MSDN documentation for the DomainContext object no longer mentions the method although it is still there? I'm not sure if this is a case of the documentation lagging behind or an indication that I shouldn't 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
        }
    }
}
+1  A: 

For reference the code below nearly works but you can't access a private member using reflection in Silverlight. Wouldn't have been happy with this hack though anyway. Interesting to note that there is a WebDomainClient contructor that takes a Binding parameter private WebDomainClient(Uri serviceUri, bool usesHttps, Binding binding) but the XML Comment for this states Private constructor. Should be made public once we have an end-to-end extensibility story on top of WCF. Looks like I'll have to wait a while before they get to exposing this kind of configuration to us.

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);
    }
}
Martin Hollingsworth
A: 

Hello Mr. Hollingsworth,

Were you able to find a solution to this problem? I dont known much about reflection, but could you once you have an instance of the WebDomainClient serialize it, send it to the server, deserialize it, have it changed, serialize it, send it back to the SL client, deserialize it and then use it? Just a tought.

Alain Hogue
+2  A: 

Hello, the answer is here:

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

Either one line after domain context creation:

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

or a 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);
   }
}
Jonx
I'm not working on this code base any longer but it's good to know they exposed this eventually. I was working with the Beta at the time.
Martin Hollingsworth