简体   繁体   English

Silverlight 域服务超时

[英]Silverlight DomainService Timeout

I have a silverlight 5 project that invokes a method form my business logic layer (a DomainService class), this invoke method returns a string.我有一个 Silverlight 5 项目,它从我的业务逻辑层(一个 DomainService 类)调用一个方法,这个调用方法返回一个字符串。 My problem is that running this method may take couple of hours to perform and I need a way to avoid RIA timeouts.我的问题是运行此方法可能需要几个小时才能执行,我需要一种方法来避免 RIA 超时。 Any ideas?有什么想法吗?

With OpenRIAServices 5.0.0 you need to do the following使用 OpenRIAServices 5.0.0,您需要执行以下操作
Declare your own custom service factory, and tweak the timeout settings声明您自己的自定义服务工厂,并调整超时设置

public partial class MyDomainClientFactory : WebDomainClientFactory
{
   protected override Binding CreateBinding(Uri endpoint, bool requiresSecureEndpoint)
   {
       var binding = base.CreateBinding(endpoint, requiresSecureEndpoint);
       binding.SendTimeout = new TimeSpan(0, 30, 0);
       binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
       binding.OpenTimeout = new TimeSpan(0, 30, 0);
       binding.CloseTimeout = new TimeSpan(0, 30, 0);
       return binding;
   }
}

And then you use it by seting the DomainClientFactory of the DomainContext然后你通过设置 DomainContext 的 DomainClientFactory 来使用它

DomainContext.DomainClientFactory = new MyDomainClientFactory()
{
    ServerBaseUri = MyServiceVPSUri,
};

It would be wiser to implement the call in two parts.分两部分实现调用会更明智。

  1. Invoke the method to start the process, returning a token to track the status调用方法启动进程,返回一个token来跟踪状态
  2. Periodically (every 5 mins?) poll another method submitting the token and returning a status定期(每 5 分钟?)轮询另一种提交令牌并返回状态的方法

This is far superior to leaving a connection open and waiting.这远优于让连接保持打开并等待。

Another possibility is to use something like SignalR to do the polling for you.另一种可能性是使用 SignalR 之类的东西为您进行轮询。 When the server completes, you would expect to receive the result almost immediately.当服务器完成时,您会期望几乎立即收到结果。

You could make use of the OnCreated partial method for the RIA client side domain context您可以对 RIA 客户端域上下文使用 OnCreated 部分方法

public partial class DSMain
{
    partial void OnCreated()
    {
        if (Application.Current.IsRunningOutOfBrowser)
        {
            ClientHttpAuthenticationUtility.ShareCookieContainer(this);
        }

        System.ServiceModel.DomainServices.Client.WebDomainClient<Main.Services.IDSContract> dctx = this.DomainClient as System.ServiceModel.DomainServices.Client.WebDomainClient<Main.Services.IDSContract>;
        ChannelFactory factory = dctx.ChannelFactory;

        System.ServiceModel.Channels.CustomBinding binding = factory.Endpoint.Binding as System.ServiceModel.Channels.CustomBinding;
        binding.SendTimeout = new TimeSpan(0, 30, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
        binding.OpenTimeout = new TimeSpan(0, 30, 0);
        binding.CloseTimeout = new TimeSpan(0, 30, 0);

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM