Silverlight 4 Ria Services Timeout Issues

5.2k Views Asked by At

I am making a call from my Silverlight client into my DomainService that normally takes about 2 minutes. I need to extend the timeout value of the endpoint to 5 minutes to be safe, but it appears to ignore the setting and I can't find out why. Here is how I am creating my DomainContext in my client:

MyDomainContext context = new MyDomainContext();
((WebDomainClient<MyDomainContext.IMyDomainServiceContract>)context.DomainClient).ChannelFactory.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
context.Search(_myParms, p =>
    {
      if (p.HasError)
      {
        // Handle errors
      }

       // Should take about 2 min. to get here, but times out before          
     }, null);

I have tried setting the ReveiveTimeout and SendTimeout both, but I always get the error at exactly 1 minute.

Can someone tell me what I am doing wrong?

EDIT: This is the exact error I am getting:

{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass2.b_0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

I have also tested to make sure it's not something in my service. At present, I just have my service run a while loop. Again, I get this error at exactly one minute.

Thanks,

-Scott

3

There are 3 best solutions below

2
On

Could it be a request timeout on the server side web application that hosts the domain service? Check the settings of the web application where the service runs or the application pool.

1
On

You should implement partial method OnCreated() of MyDomainContex class.

Sample:

public partial class TestDomainContext
{
    partial void OnCreated()
    {
        var proxy = (WebDomainClient<Test.Server.Services.TestDomainContext.ITestDomainServiceContract>)this.DomainClient;
        proxy.ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
    }
0
On

This problem is one of the pain points in Silverlight.

I prefer an extension method for something like this rather than creating delicate partial classes.

See the solution here: http://blogs.msdn.com/b/kylemc/archive/2010/11/03/how-to-change-the-request-timeout-for-wcf-ria-services.aspx

if your using prism you can inject as follows:

_unityContainer.RegisterType<SurveyModuleContext>(new InjectionFactory(c => CreateSurveyContext()));



    private object CreateSurveyContext()
    {
        var context = new SurveyModuleContext();
        context.ChangeWcfSendTimeout(new TimeSpan(0, 10, 0));
        return context;
    }


public static class DomainContextExtensions
{
    public static void ChangeWcfSendTimeout(this 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;
    }
}

You can see in this screenshot that the solution does indeed work. (2m 1s) call

using firebug network request and response 2m 1s.