Reputation: 13
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?
Upvotes: 1
Views: 539
Reputation: 31
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,
};
Upvotes: 3
Reputation: 31
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);
}
}
Upvotes: 0
Reputation: 6932
It would be wiser to implement the call in two parts.
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.
Upvotes: 0