Custom wcf ria Services timeout

Source: Internet
Author: User

Generally, you can set the Timeout attribute value in the configuration file to customize the service Timeout time. However, the WCF Service does not have a configuration file, and the default Timeout value is 60 s. But sometimes, if our query time exceeds 60 s, can we define the time-out by ourselves.

The answer is yes. The proxy class generated by RIA Services is just partial. We can use this to set timeout.

First, create a class WcfTimeoutUtility in the Service project. Here, set the timeout method.

/// <summary>  /// Utility class for changing a domain context's WCF endpoint's  /// SendTimeout.   /// </summary>  public static class WcfTimeoutUtility  {    /// <summary>    /// Changes the WCF endpoint SendTimeout for the specified domain    /// context.     /// </summary>    /// <param name="context">The domain context to modify.</param>    /// <param name="sendTimeout">The new timeout value.</param>    public static void ChangeWcfSendTimeout(DomainContext context,                                             TimeSpan sendTimeout)    {      PropertyInfo channelFactoryProperty =        context.DomainClient.GetType().GetProperty("ChannelFactory");      if (channelFactoryProperty == null)      {        throw new InvalidOperationException(          "There is no 'ChannelFactory' property on the DomainClient.");      }      ChannelFactory factory = (ChannelFactory)        channelFactoryProperty.GetValue(context.DomainClient, null);      factory.Endpoint.Binding.SendTimeout = sendTimeout;    }  }

The default time is changed based on the features of the partial classification.

Note that the class name: MyDomainContext must be the same as the DomainContext class name in the code automatically generated by your Service, and the namespace should also be consistent with the DomainContext class in web. g. cs.

public partial class MyDomainContext  {    partial void OnCreated()    {      TimeSpan tenMinutes = new TimeSpan(0, 10, 0);      WcfTimeoutUtility.ChangeWcfSendTimeout(this, tenMinutes);    }  }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.