Silverlight Async Timeout Error

前端 未结 5 1016
半阙折子戏
半阙折子戏 2020-12-18 22:25

Calling through to my Silverlight Enabled WCF-Service in my silverlight application, occasionally users get timeouts. Whats the easiest way to boost the time allowed by the

相关标签:
5条回答
  • 2020-12-18 22:30

    The accepted answer here did not work for me. Instead I had to cast the base channel into an IContextChannel, and set the OperationTimeout on that.

    To do that, I had to create a new file with a partial class, that matched the name of the ServiceReference. In my case the I had a PrintReportsService. Code is below.

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace RecipeManager.PrintReportsService 
    {
        public partial class PrintReportsClient : System.ServiceModel.ClientBase<RecipeManager.PrintReportsService.PrintReports>, RecipeManager.PrintReportsService.PrintReports 
        {
            public void SetOperationTimeout(TimeSpan timeout)
            {
                ((System.ServiceModel.IContextChannel)base.Channel).OperationTimeout = timeout;
            }
    
    
        }
    }
    

    Then when I create the client, I do the following:

            PrintReportsService.PrintReportsClient client = new RecipeManager.PrintReportsService.PrintReportsClient();
            client.SetOperationTimeout(new TimeSpan(0, 4, 0));
    

    That did it for me! More info is available here, but the code snippet in this post doesn't compile.

    0 讨论(0)
  • 2020-12-18 22:46
    • Ammount of time connection can be open: BasicHttpBinding.OpenTimeout property
    • Time that a connection can remain inactive, during which no application messages are received, before it is dropped: BasicHttpBinding.ReceiveTimout property

    This can be set in the node of the ServiceReference.ClientConfig file in the silverlight app.

    0 讨论(0)
  • 2020-12-18 22:46

    Rather than changing the timeout, I think you should implement a timer-based callback to the server from the Silverlight application so that the session doesn't expire. This would eliminate the overhead of longer timeouts for all of your application.

    0 讨论(0)
  • 2020-12-18 22:47

    I fixed this by enabling compatibility mode in IE

    0 讨论(0)
  • This can be set, but there is an upper limit that is defined by the underlying HTTP library (I think its five minutes). Note that using a higher value will fall back to what the upper limit is. Also, be aware that you may need to configure the timeout on the server as well.

    0 讨论(0)
提交回复
热议问题