ASP.NET MVC async call a WCF service.
Posted
by mmcteam
on Stack Overflow
See other posts from Stack Overflow
or by mmcteam
Published on 2010-03-18T12:54:18Z
Indexed on
2010/03/18
13:01 UTC
Read the original article
Hit count: 735
Hi all. After complete of asynchronous call to WCF service I want set success message into session and show user the notification .
I tried use two ways for complete this operation.
1) Event Based Model.
client.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(GetDataCompleted);
client.GetDataAsync(id, client);
private void GetDataCompleted(object obj, GetDataCompletedEventArgs e)
{
this.SetNotification(new Notification() { Message = e.Result, Type = NotificationType.Success });
}
In MyOperationCompleted event i can set notification to HttpContext.Current.Session, but I must waiting before this operation will completed and can't navigate to others pages.
2) IAsyncResult Model.
client.BeginGetData(id, GetDataCallback, client);
private void GetDataCallback(IAsyncResult ar) {
string name = ((ServiceReference1.Service1Client)ar.AsyncState).EndGetData(ar);
this.SetNotification(new Notification() { Message = name, Type = NotificationType.Success });
}
"Generate asynchronous operations" in service reference enabled.
Please help me with this trouble. I novice in ASP.NET MVC. Thanks.
© Stack Overflow or respective owner