2011-02-02 145 views
0

我正在从我的Silverlight客户端调用我的DomainService,通常需要2分钟。我需要将端点的超时值延长到5分钟才能安全,但似乎忽略了该设置,我找不到原因。这里是我如何在我的客户创造我DomainContext:Silverlight 4 Ria服务超时问题

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); 

我已经尝试设置ReveiveTimeout和双方的SendTimeout,但我总是在完全相同1分钟得到错误。

有人能告诉我我做错了什么吗?

编辑:这是我得到确切的错误:

{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)}

我还测试,以确保它不是在我的服务。目前,我只是让我的服务运行一段时间。再一次,我正好在一分钟内得到这个错误。

感谢,

斯科特

回答

2

你应该实现分部方法MyDomainContex类的OnCreated()。

样品:

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

不幸的是,这并没有奏效。在一分钟之后,我仍然会收到同样的错误。我已更新我的原始帖子,以显示我正在收到的确切错误。 – Scott 2011-02-02 19:02:01

0

难道是在承载域服务的服务器端Web应用程序的请求超时?检查运行服务的Web应用程序或应用程序池的设置。

+0

我的DomainServices目前正在Visual Studio的内部Web服务器中托管。有没有办法改变VS中的超时值?这可能是问题... – Scott 2011-02-02 19:55:22

1

这个问题是Silverlight中的一个难点。

我更喜欢这样的东西的扩展方法,而不是创建微妙的部分类。如果您使用棱镜 http://blogs.msdn.com/b/kylemc/archive/2010/11/03/how-to-change-the-request-timeout-for-wcf-ria-services.aspx

你可以注入如下:

见这里的解决方案

_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; 
    } 
} 

您可以在这张截图,该解决方案确实看到工作。 (2m 1s)电话

using firebug network request and response 2m 1s.