Exceeded the allotted timeout

I Developed a system with Silverlight 4 and  Ria Service.
All runs fine, however when it takes more than 60 seconds the application side client stops,  receiving the message bellow, but the process on the server side runs normaly until the end.
How to configure this time?
Thanks.

Message:
Caused by: Invoke Operation 'MontarRegistrosNFe' failed. The HTTP request to 'http://localhost:52878/ClientBin/NFe-Web-NFeDomainService.svc/binary/MontarRegistrosNFe' has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout.

PlexoAsked:
Who is Participating?
 
vbighamCommented:
I built a test project with the same name as yours and can show you a couple things about what this solution entails.

Add a file to your silverlight project called:  RiaExtendTimeOutUtility.cs  and copy the following code into that file.
 
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;
using System.ServiceModel.DomainServices.Client;
using System.Reflection;
using System.ServiceModel;


namespace SimulaTimeOut
{
    public static class RiaExtendTimeOutUtility
    {
        public static void ChangeRiaSendTimeout(DomainContext ctx, TimeSpan sendTimeout)
        {
            PropertyInfo channelFactoryProperty = ctx.DomainClient.GetType().GetProperty("ChannelFactory");

            if (channelFactoryProperty == null)
            {
                throw new InvalidOperationException("There is no 'ChannelFactory' property on the DomainClient.");
            }

            ChannelFactory factory = (ChannelFactory)channelFactoryProperty.GetValue(ctx.DomainClient, null);

            factory.Endpoint.Binding.SendTimeout = sendTimeout;
        }
    }
}

Open in new window



I created an empty Domain service class in the web project.  It just sleeps the thread like you suggested then returns an integer.  Here is what that looks like.  I called this file ExtraLengthyDomainService.cs
namespace SimulaTimeOut.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class ExtraLengthyDomainService : DomainService
    {
        [Invoke()]
        public Int32 GetRandomInteger()
        {
            System.Threading.Thread.Sleep(120000);
            return 1000;
        }
    }
}

Open in new window


Now I have added another file to the Silverlight project called: ExtraLengthyDomainContext.cs
This is the extension of the already generated ExtraLengthyDomainContext, and here is what that looks like:
NOTE: To make the Namespace match all I had to do was add ".Web"  If your domain service class is in another namespace you would add that after the ".Web", for example if it resides in "Services" you would add ".Web.Services".  This is important to make sure that this code applies to the same object.
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 SimulaTimeOut.Web
{
    public partial class ExtraLengthyDomainContext
    {
        partial void OnCreated()
        {
            // Set a break point to ensure that it works (must have the matching namespace)
            TimeSpan tenMinutes = TimeSpan.FromMinutes(10);
            RiaExtendTimeOutUtility.ChangeRiaSendTimeout(this, tenMinutes);
        }
    }
}

Open in new window

Now, whenever you instantiate a context of this type, it will have the extended timeout.

Then I have just created my context in code in the main page just for testing.  When I comment out the "partial void OnCreated()" method the call has the timeout error.  But as long as that method extends the timeout, the invoke operation comes back fine.  Here is the MainPage.xaml.cs:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;

namespace SimulaTimeOut
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Web.ExtraLengthyDomainContext ctx = new Web.ExtraLengthyDomainContext();

            InvokeOperation<Int32> invOp = ctx.GetRandomInteger();
            invOp.Completed +=new EventHandler(invOp_Completed);            
        }

        void invOp_Completed(object sender, EventArgs e)
        {
            InvokeOperation<Int32> invOp = sender as InvokeOperation<Int32>;

            if (invOp.HasError)
            {
                MessageBox.Show(invOp.Error.Message);
                invOp.MarkErrorAsHandled();
            }
            else
            {
                MessageBox.Show(invOp.Value.ToString());
            }
        }
    }
}

Open in new window

0
 
dquebeCommented:
Are you using wcf for the web service, and do you have access to the web.config? There are timeout settings on both the server and client with wcf.
0
 
PlexoAuthor Commented:
Hi dquebe.
I´m not using wcf for web service. I´m using Ria Service.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
dquebeCommented:
I have used Silverlight with WCF, and I believe that RIA uses WCF for the services. I don't know about the server service in your configuration. But I would do the following as next steps (hopefully this helps), identify what the host service is running (old ASP Web Services or new WCF Services). Look at how you attached to the server Service (e.g. did you "Add a Service Reference"). Look for your .config file for the client if you used "Add". It could be under "app.config", "web.config" or "ServiceReferences.ClientConfig". The timeout sounds like the standard timeout period for the client. I have the following code to set the timeouts on my client, but you could do it in the Config file on the binding itself (binding is a reference to the binding that I am using at that time [e.g. System.ServiceModel.BasicHttpBinding] where minutes is a parameter [int] that defines how long I want to wait).


            binding.CloseTimeout = new TimeSpan (0, 1, 0);

            binding.OpenTimeout = new TimeSpan (0, 1, 0);

            binding.ReceiveTimeout = new TimeSpan (0, minutes, 0);

            binding.SendTimeout = new TimeSpan (0, minutes, 0);

0
 
dquebeCommented:
If you find the "ServiceReferences.ClientConfig" or find one of the other configs, go under the <system.serviceModel><bindings><[bindingtype]<binding> and add an attribute for "receiveTimeout".
0
 
PlexoAuthor Commented:
Hi dquebe.

Thank you for your attention.

I had already put the following in the webconfig, but don't change anything.

<bindings>
      <wsHttpBinding>
        <binding
            closeTimeout="00:10:00"
            openTimeout="00:010:00"
            receiveTimeout="00:010:00"
            sendTimeout="00:010:00">
        </binding>
      </wsHttpBinding>
    </bindings>

I did not find any other config, like ServiceReferences.ClientConfig or app app.config.

Thanks
0
 
PlexoAuthor Commented:
Hi tovvenki,

I did not find where I can puts the command cited:

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

Do you have an idea where is the "domain context creation" ?

Attached is a print of Solution Explorer.

Thanks

Experts.JPG
0
 
vbighamCommented:
The domain context creation exists in the generated code.  In order to override it you will need to create a partial class that extends the auto-generated class.  These examples also seems to work for me after I first initialize the domaincontext object before I query anything.

I felt that this one:
http://blogs.msdn.com/b/kylemc/archive/2010/11/03/how-to-change-the-request-timeout-for-wcf-ria-services.aspx

was a bit more explicit and easier to understand what was going on.  I was also able to notice that if I set the SendTimeout to 20 min that the RecieveTimeout was set to 10 min.

What I did was create a method called GetDomainContextWithExtendedTimeout() which initialized a MyDomainContext and then set the timeout on the channelfactory binding then I could use the returned value to load my time intensive query.

Hope this helps,
Vaughn
0
 
PlexoAuthor Commented:
Hi vbigham.

I think that the example is for WebServices, and that WCF Ria Service is not the same Ria Service for Silverligh 4.
I did not find the places mentioned in my project.
I´m using Ria Services and Silverlight 4.

Thanks
0
 
vbighamCommented:
They are one and the same, fyi .NET Ria Services is now called WCF Ria Services.  The reason that you have not found those places would be because you have not created them yet.  What that blog post is showing is to create a static class with a static method that increases the timeout on a domaincontext object.  Then he extends his generated domain context by declaring a "Partial Public Class MyDomainContext" which also extends the OnCreated using a partial method.  All of that to make sure that the endpoint does not get used before the timeout has been set.  This would also be appropriate if you are declaring your DomainContext in xaml using Ria Controls.  If you are declaring your context in code you can create it and then probably call that one liner just after it is instantiated.

I can help you make it work.  If you wouldn't mind just post the code or the xaml of the Ria Context / Controls that would eventually be getting the timeout error and I can give you some steps and some code to increase the timeout.
0
 
PlexoAuthor Commented:
Hi Vaughn.
Thanks for your atention.
I have a simple project simulating the problem. It use thread.sleep for to cause the situation.
How can I send to you ?
I made a .zip file and I tried send by attachment, but I received the message:
 "The extension of one or more files in the archive is not in the list of allowed extensions: SimulaTimeOut/SimulaTimeOut/App.xaml"

Regards,
Sidney


Regards,
Sidney

0
 
vbighamCommented:
I'm not sure how we can share a project.  I don't have an email address that will accept source code either (It all gets rejected).  

One thing we can do though.. If you will post another screen shot with this test project structure (solution explorer).  Then just post the code for the domain service class that simulates the problem.  I will recreate the project really quick and post the exact steps and code to resolve in the test project so that you can see exactly how to do it in your actual project.

Thanks,
Vaughn
0
 
PlexoAuthor Commented:
Hi Vaughn .

Now I understood.
Thanks for the example.

Regards,
Sidney
0
 
PlexoAuthor Commented:
Sorry I was mistaken in point.
How can I repeat?
0
 
PlexoAuthor Commented:
Now the score is right.
Thanks
0
 
vbighamCommented:
Glad to help, thank you very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.