【问题标题】:Silverlight 4 Ria Services Timeout IssuesSilverlight 4 Ria 服务超时问题
【发布时间】:2011-02-02 16:55:18
【问题描述】:

我正在从我的 Silverlight 客户端调用我的 DomainService,这通常需要大约 2 分钟。为了安全起见,我需要将端点的超时值延长到 5 分钟,但它似乎忽略了该设置,我无法找出原因。以下是我在客户端中创建 DomainContext 的方式:

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:远程服务器返回错误:NotFound。 ---> System.Net.WebException:远程服务器返回错误:NotFound。 在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.BrowserHttpWebRequest.c_DisplayClass5.b_4(对象 sendState) 在 System.Net.Browser.AsyncHelper.c_DisplayClass2.b_0(对象 sendState) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,对象状态) 在 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult 结果)}

我还进行了测试,以确保它不在我的服务范围内。目前,我只是让我的服务运行一个 while 循环。同样,我在一分钟内收到此错误。

谢谢,

-斯科特

【问题讨论】:

    标签: silverlight wcf entity-framework timeout wcf-ria-services


    【解决方案1】:

    你应该实现 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);
        }
    

    【讨论】:

    • 不幸的是,这不起作用。整整一分钟后,我继续收到相同的错误。我已经更新了我的原始帖子以显示我得到的确切错误。
    【解决方案2】:

    这个问题是 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) 调用

    【讨论】:

      【解决方案3】:

      可能是托管域服务的服务器端 Web 应用程序的请求超时?检查运行服务的 Web 应用程序或应用程序池的设置。

      【讨论】:

      • My DomainServices 目前托管在 Visual Studio 的内部 Web 服务器中。有没有办法改变VS中的超时值?这可能是问题...
      • 尝试在httpRuntime配置中设置执行超时。但是我不知道这对内部服务器是否有帮助:
      猜你喜欢
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 2012-09-06
      • 1970-01-01
      相关资源
      最近更新 更多