F
Frank Mamone
Hi,
I am using this code to call a Web Service (from Amit Kalani's book) and
everything works except when that the ListBox referenced in the
WebServiceCallback method does not fill in the ListBox.
This is a really strange one because all the lines execute and I can see all
the values being assigned using Watches.
Here is the complete page code.
namespace WebAsync
{
/// <summary>
/// Summary description for WebServiceAsync.
/// </summary>
public class WebServiceAsync : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtCode;
protected System.Web.UI.WebControls.Button btnGetWeather;
protected System.Web.UI.WebControls.ListBox lbResults;
private void Page_Load(object sender, System.EventArgs e)
{
// This works
if(!IsPostBack)
lbResults.Items.Add("Hello");
}
#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.btnGetWeather.Click += new
System.EventHandler(this.btnGetWeather_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnGetWeather_Click(object sender, System.EventArgs e)
{
com.capescience.live.AirportWeather aw = new
com.capescience.live.AirportWeather();
AsyncCallback wcb = new AsyncCallback(WebServiceCallback);
IAsyncResult ar = aw.BegingetSummary(txtCode.Text,wcb,aw);
ar.AsyncWaitHandle.WaitOne();
}
public void WebServiceCallback(IAsyncResult ar)
{
//This debugging line does not work either
lbResults.Items.Add("I'm back");
com.capescience.live.AirportWeather aw =
(com.capescience.live.AirportWeather) ar.AsyncState;
com.capescience.live.WeatherSummary ws = aw.EndgetSummary(ar);
lbResults.Items.Clear();
lbResults.Items.Add(ws.location);
lbResults.Items.Add(ws.wind);
lbResults.Items.Add(ws.sky);
lbResults.Items.Add(ws.temp);
lbResults.Items.Add(ws.humidity);
lbResults.Items.Add(ws.pressure);
lbResults.Items.Add(ws.visibility);
}
}
}
I am using this code to call a Web Service (from Amit Kalani's book) and
everything works except when that the ListBox referenced in the
WebServiceCallback method does not fill in the ListBox.
This is a really strange one because all the lines execute and I can see all
the values being assigned using Watches.
Here is the complete page code.
namespace WebAsync
{
/// <summary>
/// Summary description for WebServiceAsync.
/// </summary>
public class WebServiceAsync : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtCode;
protected System.Web.UI.WebControls.Button btnGetWeather;
protected System.Web.UI.WebControls.ListBox lbResults;
private void Page_Load(object sender, System.EventArgs e)
{
// This works
if(!IsPostBack)
lbResults.Items.Add("Hello");
}
#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.btnGetWeather.Click += new
System.EventHandler(this.btnGetWeather_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnGetWeather_Click(object sender, System.EventArgs e)
{
com.capescience.live.AirportWeather aw = new
com.capescience.live.AirportWeather();
AsyncCallback wcb = new AsyncCallback(WebServiceCallback);
IAsyncResult ar = aw.BegingetSummary(txtCode.Text,wcb,aw);
ar.AsyncWaitHandle.WaitOne();
}
public void WebServiceCallback(IAsyncResult ar)
{
//This debugging line does not work either
lbResults.Items.Add("I'm back");
com.capescience.live.AirportWeather aw =
(com.capescience.live.AirportWeather) ar.AsyncState;
com.capescience.live.WeatherSummary ws = aw.EndgetSummary(ar);
lbResults.Items.Clear();
lbResults.Items.Add(ws.location);
lbResults.Items.Add(ws.wind);
lbResults.Items.Add(ws.sky);
lbResults.Items.Add(ws.temp);
lbResults.Items.Add(ws.humidity);
lbResults.Items.Add(ws.pressure);
lbResults.Items.Add(ws.visibility);
}
}
}