Changing timeouts in WCF RIA Services

This article is valid for the RC version and above

In previous versions of WCF RIA Services, it was extremely difficult to change the service timeouts for your DomainService, you were pretty much stuck with the defaults.  The RC release has made it fairly easy, though not all that discoverable.

The single line of code you need is:

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

There are two options on where to put this line of code.  First is anywhere after you construct a DomainContext, in which case change ‘this’ to the name of your context object. 

The second choice is to create a partial class for your DomainContext and use the partial method OnCreated, which would look like this:

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

If you are not sure of the interface you should be using on WebDomainClient, take a look at the constructor of your DomainContext, it is calling the base constructor with the proper WebDomainClient that you should be using above.

EDIT: March 31st 2010

I added a Designer check to the code, this will stop exceptions from being thrown during design time.  If you found this post for some other reason than WCF RIA Services RC (or higher) be aware that the above designer check has issues with older versions of Visual Studio.  Read this post from Delay's Blog for info