Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a Silverlight3 application whcih is using WCF. I am calling one service which is defined in the wcf from my silverlight application recursively.

The problem is - here I am facing is that before getting the result of the first call, it is activating the second call. So some times I am getting the result of the second Call(call to wcf) befor getting the result of first call. I know that silverlight support only Sync call. But in this situation how I can handle the program flow.

Here is the details:
C#
Silverlight appln
{
//Recursive call
    while(i<3)
    {
    callWCFAsync() //
    //do some work-- Here I want to do some work based on the result of 1 call, then based on the result of 2 call, then based on the result of 3 call(otherwise it should invoke the second call(in second iteration),only after getting the result of first call)-- How I can achieve it....??
    }
}

WCF
{
definition of callWCFAsync()
{
}
}

Please help me on this.

Thanks in Advance... :) :)
Posted
Updated 19-Feb-11 20:17pm
v2

This is very easy. Call the second service only when the call to the first service returns. This is the only way to guarantee you have the results for the first call available when the second one starts execution in asynchronous calls in SL.

Best of luck!
 
Share this answer
 
Comments
Arun India 20-Feb-11 3:58am    
First of all Thanks Abhinav for your reply. But Abhinav, see I am calling the service recursively. Then how I can ensure that the first call is completed before the second call..??
Abhinav S 20-Feb-11 6:44am    
I think you need to look at the way this is done. Calling services recursively is definitely not a good idea.
Espen Harlinn 20-Feb-11 10:25am    
Right, my 5
Arun India 20-Feb-11 10:48am    
But Abhinav, we need to handle this kind of situations, for example in the case of treeView, if I write the code to load the children of a "Treeview node" in "OnTreeViewNodeExpand" event, then suppose I want to expand all the node, then before getting the children of the first TreeViewNode it will call for the next node's children.So the result won't come as we expect. Then how we can handle it...Please help..
Abhinav S 20-Feb-11 11:32am    
If you are going to load the children on every node click, the system is going to be very slow.
Try loading the entire data inside the treeview in one service call - then play around with it in the treeview. Try avoiding calling the service on every node click. It will make the user wait and become very impatient.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900