【问题标题】:Getting WCF RIA Service Timeout获取 WCF RIA 服务超时
【发布时间】:2013-05-17 07:49:19
【问题描述】:

我正在运行繁重的 WCF RIA 服务操作并在客户端 Silverlight 应用程序上收到此类错误:

    Uncaught Error: Unhandled Error occurred in Silverlight Application:
Submit operation failed. Для запроса HTTP к 

"https://localhost/MyProject/ClientBin/myservice.svc/binary" has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout.


Stack Trace:
   в System.Windows.Ria.OperationBase.Complete(Exception error)
   в System.Windows.Ria.SubmitOperation.Complete(Exception error)
   в System.Windows.Ria.DomainContext.CompleteSubmitChanges(IAsyncResult asyncResult)
   в System.Windows.Ria.DomainContext.<>c__DisplayClassd.<SubmitChanges>b__5(Object )

我在执行 1 分钟后就遇到了这样的超时。

我的上下文是这样的:

[EnableClientAccess()]
public class ConfigService : LinqToEntitiesDomainService<MyEntityFrameworkEntities>

这是代码截图:

【问题讨论】:

  • 你应该在你的代码中添加端点:factory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 10, 0);
  • 我有两个方法的工厂:ReleaseDomainService 和 CreateDomainService。没有其他的。让我尝试投射到 ChannelFactory
  • 我不知道 RIA Beta 对不起兄弟....
  • 如果你喜欢我的研究,请点赞我....你的好兄弟....

标签: wcf silverlight silverlight-3.0 wcf-ria-services wcf-configuration


【解决方案1】:

本主题中讨论的所有设置都是在绑定本身上进行的,无论是在代码中还是在配置中。以下代码显示了如何在自托管服务的上下文中以编程方式设置 WCF 绑定超时。

public static void Main()
            {
                Uri baseAddress = new Uri("http://localhost/MyServer/MyService");

                try
                {
                    ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));

                    WSHttpBinding binding = new WSHttpBinding();
                    binding.OpenTimeout = new TimeSpan(0, 10, 0);
                    binding.CloseTimeout = new TimeSpan(0, 10, 0);
                    binding.SendTimeout = new TimeSpan(0, 10, 0);
                    binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

                    serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);
                    serviceHost.Open();

                    // The service can now be accessed.
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.WriteLine();
                    Console.ReadLine();

                }
                catch (CommunicationException ex)
                {
                    // Handle exception ...
                }
            }

以下示例显示了如何在配置文件中对绑定配置超时。

<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding openTimeout="00:10:00" 
                 closeTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 receiveTimeout="00:10:00">
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

你应该编辑 RIA 服务

域上下文创建后的任一行:

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

或部分类

public partial class LibraryDomainContext
{
   partial void OnCreated()
   {
      if(DesignerProperties.GetIsInDesignMode(App.Current.RootVisual))
         ((WebDomainClient<LibraryDomainContext.ILibraryDomainServiceContract>)this.DomainClient).ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
   }
}

【讨论】:

  • 实际上这个错误更多地与RIA服务有关,而不是一般意义上的WCF
  • 我用 LinqToEntitiesDomainService 扩展了我的自定义类
  • 如果我使用 RIA Release 版本,这可能是一个答案
  • 公共部分类 LibraryDomainContext { partial void OnCreated() { if(DesignerProperties.GetIsInDesignMode(App.Current.RootVisual)) ((WebDomainClient)this.DomainClient).ChannelFactory.Endpoint。 Binding.SendTimeout = new TimeSpan(0, 5, 0); } } 嗨,老兄!这行得通!但是 ChannelFactory 是非公开的....
【解决方案2】:

从客户端调用时,您希望增加 sendTimeout 属性。

closeTimeout = 关闭连接的时间间隔

openTimeout = 连接打开的时间间隔

receiveTimeout = 服务允许连接处于非活动状态的时间间隔

sendTimeout = 客户端等待响应的时间间隔

【讨论】:

猜你喜欢
  • 2011-01-14
  • 2013-05-12
  • 2011-06-21
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 2011-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多