WCF blocking call
I am using WCF DataService I have a method:
[OperationContract]
public List<string> GetAges()
{
return _registrationData.GetAges();
}
on my client side, I instantiate it this way:
_registrationDataServices = new RegistrationDataServiceClient();
it now exposes a delegate
_registrationDataServices.GetAgesCompleted += GetAgesCompleted;
and a function call:
_registrationDataServices.GetAgesAsync()
the problem with this is that the call to the service will be asynchronous and the results comes in the delegate function, I want to be able to call the service and wait (block) until the results come back, how can this be done using WCF ?
I have to use a wcf, because I have a silverlight application that needs data from a database, the WCF is being called from a .NET a开发者_开发知识库ssembly as my data access layer.
It is a very bad practice to call web service from a Silverlight/WPF application synchronously. The sync call would hang your UI until the web service call has ended, which will cause bad user experience. However, if you're still up for it, here is a very helpful link.
Don't call it synchronously -- you will block the UI thread. Users usually think their software has crashed if the UI is frozen.
Ideally you would make a modal busy indicator that animates and shows 'progress' while you wait for the call to come back, and it goes away when you receive the Completed event.
Even if you were still convinced that blocking the UI thread was OK in your case, you can't actually call it synchronously! It was designed this way for a reason - go with the flow.
精彩评论