Question

I have a silverlight 5 project that invokes a method form my business logic layer (a DomainService class), this invoke method returns a string. My problem is that running this method may take couple of hours to perform and I need a way to avoid RIA timeouts. Any ideas?

Était-ce utile?

La solution 2

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
  2. Periodically (every 5 mins?) poll another method submitting the token and returning a status

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. When the server completes, you would expect to receive the result almost immediately.

Autres conseils

With OpenRIAServices 5.0.0 you need to do the following
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 = new MyDomainClientFactory()
{
    ServerBaseUri = MyServiceVPSUri,
};

You could make use of the OnCreated partial method for the RIA client side domain context

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

    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top