Answered by:
How to Chain async call's

Question
-
We are trying to call the web service which in turn call's another web service. The problem we are facing here is the web service is a async and it can't wait for the another web service call back,But we get the data only after the second web service call back and that data we have to push it to the first service call back. So Is there any mechanism to make the first web service to wait till the second completes .
NOTE: We tried the following link but we are unable to overcome from the issue.
http://msdn.microsoft.com/en-us/library/dwba7yy7(v=vs.80).aspx.
Thanks & Regards
Thursday, December 5, 2013 6:07 AM
Answers
-
Hi,
If you wan to make the first web service to wait until the second completes, maybe you can try the following:
IAsyncResult ar = request.BeginGetResponse(new AsyncCallback(Callback), request); ar.AsyncWaitHandle.WaitOne(5000);
In this particular case I am using the timed out version of
WaitOne()
which returns true if the wait was successful. You could use any of theWaitOne()
overloads though.Or please try to use the IsCompleted property of the IAsyncResult returned by the asynchronous operation's BeginOperationName method which will determine whether the operation has completed. If completed, then let it await.
For more information, please try to refer to:
#Polling for the Status of an Asynchronous Operation:
http://msdn.microsoft.com/en-us/library/ms228968.aspx .#Using an AsyncCallback Delegate to End an Asynchronous Operation:
http://msdn.microsoft.com/en-us/library/ms228972.aspx .Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- Edited by Amy PengMicrosoft employee, Moderator Friday, December 6, 2013 7:06 AM
- Marked as answer by Yanping Wang Tuesday, December 24, 2013 6:10 AM
Friday, December 6, 2013 7:03 AMModerator
All replies
-
Hi,
If you wan to make the first web service to wait until the second completes, maybe you can try the following:
IAsyncResult ar = request.BeginGetResponse(new AsyncCallback(Callback), request); ar.AsyncWaitHandle.WaitOne(5000);
In this particular case I am using the timed out version of
WaitOne()
which returns true if the wait was successful. You could use any of theWaitOne()
overloads though.Or please try to use the IsCompleted property of the IAsyncResult returned by the asynchronous operation's BeginOperationName method which will determine whether the operation has completed. If completed, then let it await.
For more information, please try to refer to:
#Polling for the Status of an Asynchronous Operation:
http://msdn.microsoft.com/en-us/library/ms228968.aspx .#Using an AsyncCallback Delegate to End an Asynchronous Operation:
http://msdn.microsoft.com/en-us/library/ms228972.aspx .Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- Edited by Amy PengMicrosoft employee, Moderator Friday, December 6, 2013 7:06 AM
- Marked as answer by Yanping Wang Tuesday, December 24, 2013 6:10 AM
Friday, December 6, 2013 7:03 AMModerator -
you can chain it by using its completed event
call first web service on completed event of second oneproxy.Call1Async(); proxy.Call1Completed+=CallCompleted;
void CallCompleted(object sender, CallCompletedEventArgs e)
{}
Friday, December 6, 2013 1:57 PM