Asynchronous Call ...
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngwebservices' list.


Djindo Lee
Hi,
have been trying to make asynchronous call to webservices from an asp.net
page and display different messages between the BeginMethod() and
EndMethod().
For example:
- Begin Call to asynchronous webservice
- Display message in Label1 "Please wait..."
- Get Call Back from webservice
- Get the return value from End Method
- Update Label1 with returned value.(or display return value on another
label);

On my webform this process does not work.

However I have tried the samething in a webform or a console application and
it works perfectly. Does any one know how I could make this work in a
webform ????

thanks in advance,

Djindo

PS: Here is my code

//page.aspx.cs code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyWeb
{
/// <summary>
/// Summary description for AsynchronuousCall.
/// </summary>
public class AsynchronuousCall : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
private localhost.TestService ws;
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
ws= new localhost.TestService();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
AsyncCallback AsyncCB= new AsyncCallback(MyCallBack);
IAsyncResult AsyncResult= ws.BeginGetStockQuote("MSFT",5,AsyncCB,null);
Label1.Text= "Please Wait, Searching for information ......";
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private void MyCallBack(System.IAsyncResult AsyncResult)
{
string ReturnValue;
ReturnValue = ws.EndGetStockQuote(AsyncResult);
Label2.Text="Stock Quote = " + ReturnValue;
}
}
}

//Webservice code

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace MyServices
{
/// <summary>
/// Summary description for TestService.
/// </summary>
public class TestService : System.Web.Services.WebService
{
public TestService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod(Description="Returns a stock quote")]
public string GetStockQuote(string TickerSymbol, int DelayInSeconds)
{
//Create a delay to simulate a long-running process
if (DelayInSeconds > 0)
{
//Have the thread sleep based on the DelayInSeconds parameter
//Note: The constant "1000" is to convert seconds to milliseconds
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
}
//Retrieve the stock quote based on the TickerSymbol parameter
//NOTE: Stock values are for simulation purposes only
string Quote;
switch (TickerSymbol.ToUpper())
{
case "MSFT":
Quote = "67";
break;
case "SUNW":
Quote = "36 31/32";
break;
case "IBM":
Quote = "80";
break;
case "ORCL":
Quote = "25 1/32";
break;
case "CSCO":
Quote = "51";
break;
default:
Quote = "Unknown";
break;
}
//Return value of Quote to calling application
return Quote;
}
}
}
Reply to this message...
 
    
Dunne, Joe
Hi, the reason this won't work for a webform is that the client [for the
webservice] in this case is the webserver itself which will not return
rendered output to the end client until all calls in its code have
completed.
The only way to get async calls to work is to actaully call the
webservice directly from the end client and not via the webserver. This can
be done with Javascript & xmlhttp request object, MS Soap Toolkit or other
Soap implementations.
Good luck.

IE 5.5 and above sample using JS to send Soap request directly to
webservice.
http://scootasp.net/bloggsie/ping/client.asp
<http://scootasp.net/bloggsie/ping/client.asp>

Webservice at
http://scootasp.net/bloggsie/ping/wsping.asmx
<http://scootasp.net/bloggsie/ping/wsping.asmx>

HTH

joe

-----Original Message-----
From: Djindo Lee [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 02, 2002 8:35 AM
To: aspngwebservices
Subject: [aspngwebservices] Asynchronous Call ...

Hi,
have been trying to make asynchronous call to webservices from an asp.net
page and display different messages between the BeginMethod() and
EndMethod().
For example:
- Begin Call to asynchronous webservice
- Display message in Label1 "Please wait..."
- Get Call Back from webservice
- Get the return value from End Method
- Update Label1 with returned value.(or display return value on another
label);

On my webform this process does not work.

However I have tried the samething in a webform or a console application and
it works perfectly. Does any one know how I could make this work in a
webform ????

thanks in advance,

Djindo

PS: Here is my code

//page.aspx.cs code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyWeb
{
/// <summary>
/// Summary description for AsynchronuousCall.
/// </summary>
public class AsynchronuousCall : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
private localhost.TestService ws;
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
ws= new localhost.TestService();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
AsyncCallback AsyncCB= new AsyncCallback(MyCallBack);
IAsyncResult AsyncResult= ws.BeginGetStockQuote("MSFT",5,AsyncCB,null);
Label1.Text= "Please Wait, Searching for information ......";
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private void MyCallBack(System.IAsyncResult AsyncResult)
{
string ReturnValue;
ReturnValue = ws.EndGetStockQuote(AsyncResult);
Label2.Text="Stock Quote = " + ReturnValue;
}
}
}

//Webservice code

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace MyServices
{
/// <summary>
/// Summary description for TestService.
/// </summary>
public class TestService : System.Web.Services.WebService
{
public TestService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod(Description="Returns a stock quote")]
public string GetStockQuote(string TickerSymbol, int DelayInSeconds)
{
//Create a delay to simulate a long-running process
if (DelayInSeconds > 0)
{
//Have the thread sleep based on the DelayInSeconds parameter
//Note: The constant "1000" is to convert seconds to milliseconds
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
}
//Retrieve the stock quote based on the TickerSymbol parameter
//NOTE: Stock values are for simulation purposes only
string Quote;
switch (TickerSymbol.ToUpper())
{
case "MSFT":
Quote = "67";
break;
case "SUNW":
Quote = "36 31/32";
break;
case "IBM":
Quote = "80";
break;
case "ORCL":
Quote = "25 1/32";
break;
case "CSCO":
Quote = "51";
break;
default:
Quote = "Unknown";
break;
}
//Return value of Quote to calling application
return Quote;
}
}
}

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Sachidanandam E K
Check this links..
http://www.c-sharpcorner.com/Code/2002/Feb/NTierDevelopmentWithNetP3.asp
Well,a lot of samples on this Asynchronous are already there in
http://www.c-sharpcorner.com/.
Try out..

Hope this helps!!

Sachidanandam.E.K
Member Techinical Staff

HCLT KT-ODC
Click here to reveal e-mail address
-----Original Message-----
From: Djindo Lee [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 02, 2002 7:05 PM
To: aspngwebservices
Subject: [aspngwebservices] Asynchronous Call ...

Hi,
have been trying to make asynchronous call to webservices from an asp.net
page and display different messages between the BeginMethod() and
EndMethod().
For example:
- Begin Call to asynchronous webservice
- Display message in Label1 "Please wait..."
- Get Call Back from webservice
- Get the return value from End Method
- Update Label1 with returned value.(or display return value on another
label);

On my webform this process does not work.

However I have tried the samething in a webform or a console application
and it works perfectly. Does any one know how I could make this work in a
webform ????

thanks in advance,

Djindo

PS: Here is my code

//page.aspx.cs code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyWeb
{
/// <summary>
/// Summary description for AsynchronuousCall.
/// </summary>
public class AsynchronuousCall : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
private localhost.TestService ws;
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
ws= new localhost.TestService();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
AsyncCallback AsyncCB= new AsyncCallback(MyCallBack);
IAsyncResult AsyncResult= ws.BeginGetStockQuote("MSFT",5,AsyncCB,null);
Label1.Text= "Please Wait, Searching for information ......";
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private void MyCallBack(System.IAsyncResult AsyncResult)
{
string ReturnValue;
ReturnValue = ws.EndGetStockQuote(AsyncResult);
Label2.Text="Stock Quote = " + ReturnValue;
}
}
}

//Webservice code

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace MyServices
{
/// <summary>
/// Summary description for TestService.
/// </summary>
public class TestService : System.Web.Services.WebService
{
public TestService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod(Description="Returns a stock quote")]
public string GetStockQuote(string TickerSymbol, int DelayInSeconds)
{
//Create a delay to simulate a long-running process
if (DelayInSeconds > 0)
{
//Have the thread sleep based on the DelayInSeconds parameter
//Note: The constant "1000" is to convert seconds to milliseconds
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
}
//Retrieve the stock quote based on the TickerSymbol parameter
//NOTE: Stock values are for simulation purposes only
string Quote;
switch (TickerSymbol.ToUpper())
{
case "MSFT":
Quote = "67";
break;
case "SUNW":
Quote = "36 31/32";
break;
case "IBM":
Quote = "80";
break;
case "ORCL":
Quote = "25 1/32";
break;
case "CSCO":
Quote = "51";
break;
default:
Quote = "Unknown";
break;
}
//Return value of Quote to calling application
return Quote;
}
}
}

| [aspngwebservices] member Click here to reveal e-mail address YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Joel Mueller
How is the server supposed to update HTML that has already been sent to
the browser? That's not how it works. In order to do what you want,
you'll need client-side code, and the browser will need to call the web
service, not the server. Or, you'll have to just make a synchronous
call.

-----Original Message-----
From: Djindo Lee [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 02, 2002 8:35 AM
To: aspngwebservices
Subject: [aspngwebservices] Asynchronous Call ...

Hi,
have been trying to make asynchronous call to webservices from an
asp.net page and display different messages between the BeginMethod()
and EndMethod().
For example:
- Begin Call to asynchronous webservice
- Display message in Label1 "Please wait..."
- Get Call Back from webservice
- Get the return value from End Method
- Update Label1 with returned value.(or display return value on another
label);

On my webform this process does not work.

However I have tried the samething in a webform or a console application
and it works perfectly. Does any one know how I could make this work in
a webform ????

thanks in advance,

Djindo

PS: Here is my code

//page.aspx.cs code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyWeb
{
/// <summary>
/// Summary description for AsynchronuousCall.
/// </summary>
public class AsynchronuousCall : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
private localhost.TestService ws;
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
ws= new localhost.TestService();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
AsyncCallback AsyncCB= new AsyncCallback(MyCallBack);
IAsyncResult AsyncResult= ws.BeginGetStockQuote("MSFT",5,AsyncCB,null);
Label1.Text= "Please Wait, Searching for information ......";
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private void MyCallBack(System.IAsyncResult AsyncResult)
{
string ReturnValue;
ReturnValue = ws.EndGetStockQuote(AsyncResult);
Label2.Text="Stock Quote = " + ReturnValue;
}
}
}

//Webservice code

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace MyServices
{
/// <summary>
/// Summary description for TestService.
/// </summary>
public class TestService : System.Web.Services.WebService
{
public TestService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod(Description="Returns a stock quote")]
public string GetStockQuote(string TickerSymbol, int DelayInSeconds)
{
//Create a delay to simulate a long-running process
if (DelayInSeconds > 0)
{
//Have the thread sleep based on the DelayInSeconds parameter
//Note: The constant "1000" is to convert seconds to milliseconds
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
}
//Retrieve the stock quote based on the TickerSymbol parameter
//NOTE: Stock values are for simulation purposes only
string Quote;
switch (TickerSymbol.ToUpper())
{
case "MSFT":
Quote = "67";
break;
case "SUNW":
Quote = "36 31/32";
break;
case "IBM":
Quote = "80";
break;
case "ORCL":
Quote = "25 1/32";
break;
case "CSCO":
Quote = "51";
break;
default:
Quote = "Unknown";
break;
}
//Return value of Quote to calling application
return Quote;
}
}
}

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
 
System.AsyncCallback
System.ComponentModel.IContainer
System.EventArgs
System.EventHandler
System.IAsyncResult
System.Runtime.Remoting.Messaging.AsyncResult
System.Threading.Thread
System.Web.Services.WebService
System.Web.UI.Page
System.Web.UI.WebControls.Button
System.Web.UI.WebControls.Label




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com