Increase Timeout ‘Globally’ in RIA Services

I’ve been trying to raise the timeout of our RIA project globally. After hours of struggling with trying to do it on the WCF web.config setting (WCF config is really not my strongest suit), I’ve decided to implement a code-approach solution instead. If anyone knows how to configure this within web.config, please give me a shout šŸ™‚

1. Go to the project that have WCF Ria Services Link (if you forget which project it is, you can find this out easily by checking the properties of each project).

2. Enable “Show All Files” in “Solution Explorer”.

3. Navigate to the Generated_Code Folder and find the projectname.g.cs file and open it.

4. Find the namespace and the class name of the domain context (i.e its assumed as RandomContext for this post).

5. Create a new class in this project called RandomContext.cs.

6. Append this code to the class (change the domain context name/project name/namespace to theĀ appropriateĀ name first and change the namespan as necessary):


namespace RandomServices.Web
{
    public sealed partial class RandomContext : DomainContext
    {
        partial void OnCreated()
        {
            TimeSpan timeSpan = new TimeSpan(0, 1, 0, 0);
            if (!DesignerProperties.IsInDesignTool)
            {
                ((WebDomainClient<RandomContext.IRandomServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.
                   SendTimeout = timeSpan;
                ((WebDomainClient<RandomContext.IRandomServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.
                    ReceiveTimeout = timeSpan;
                ((WebDomainClient<RandomContext.IRandomServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.
                    OpenTimeout = timeSpan;
                ((WebDomainClient<RandomContext.IRandomServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.
                    CloseTimeout = timeSpan;

            }
        }
    }
}

PS: The difference between each timeouts are as follow (taken from http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/84551e45-19a2-4d0d-bcc0-516a4041943d/):

Client side:

  • SendTimeout is used to initialize the OperationTimeout, which governs the whole interaction for sending a message (including receiving a reply message in a request-reply case).Ā  This timeout also applies when sending reply messages from a CallbackContract method.
  • OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is passed).
  • ReceiveTimeout is not used.

Server side:

  • Send, Open, and Close Timeout same as on client (for Callbacks).
  • ReceiveTimeout is used by ServiceFramework layer to initialize the session-idle timeout.
Advertisements

One comment

  1. Klaus · · Reply

    Thx, this works fine!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: