I’m implementing a Silverlight application that uses WCF services heavily, I’ve got to the point now where occasionally there are several long service calls that block other service calls from running.
These service calls eventually time out. I’d like to see if its possible to a queue system that executes service calls one after another, this way long calls will hold up other calls but won’t cause them to timeout.
I’m using service agents to wrap the service calls
public interface IExampleServiceAgent
{
void ProcessData(int a, string b, EventHandler<ProcessDataCompletedEventArgs> callback);
}
Public ExampleServiceAgent1 : IExampleServiceAgent
{
ExampleClient _Client = new ExampleClient();
public void ProcessData(int anInt, string aString, EventHandler<ProcessDataCompletedEventArgs> callback)
{
EventHandler<ProcessDataCompletedEventArgs> wrapper = null;
wrapper = (a,b) =>
{
callback(a,b);
_Client.ProcessDataCompleted -= wrapper;
}
_Client.ProcessDataCompleted += wrapper;
_Client.ProcessDataAsync(anInt,aString);
}
}
The above service agent would then be called from code as follows:
ServiceAgent.ProcessData(1,"STRING", (a,b) =>
{
if (b.Error != null)
{
//Handle Error
}
else
{
//DO something with the data
}
}
Is there a way I could put these service calls into a queue and execute them one by one?
I’ve tried wrapping them as Actions and adding them to a queue, but this does not wait for one to finish executing before starting the next one and although they do call the service correctly no data is returned to the calling ViewModel.
WCF services can cope with a huge number of calls but, to avoid denial of service attacks, the number of requests that can be processed is limited by default.
The significant limitations for Silverlight WCF services would be
This CodeProject article on Quick Ways to Boost Performance and Scalability of ASP.NET, WCF and Desktop Clients was useful.
I am guessing you are immediately hitting the first issue. In your WCF config you need to add the following to increase the single IP connections:
You may then hit the second limit for which the solution is tweak the service behaviors in the web/app.config files.
Here are a few more references I found while sorting out these issues myself: