0

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

Scott
  • 874
  • 3
  • 12
  • 36

3 Answers3

2

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);
    }
  • Unfortunately, that didn't work. I continue to get the same error after exactly one minute. I have updated my original post to show the exact error I am getting. – Scott Feb 02 '11 at 19:02
1

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.

Leblanc Meneses
  • 3,001
  • 1
  • 23
  • 26
0

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.

slfan
  • 8,950
  • 115
  • 65
  • 78
  • My DomainServices are being hosted in Visual Studio's internal web server at the moment. Is there a way to change the timeout values in VS? This could be the problem... – Scott Feb 02 '11 at 19:55
  • Try to set the execution timeout in the httpRuntime cnofiguration. However I don't know whether that helps for the internal server: – slfan Feb 03 '11 at 09:43