Problem with Asychronous Web Service Callback


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);


}

}

}
 
Ad

Advertisements

J

John Saunders

Frank Mamone said:
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.
....

//This debugging line does not work either

lbResults.Items.Add("I'm back");

Please define "does not work". Also, try Response.Write and see if that
works.
 
Ad

Advertisements

F

Frank Mamone

John,

What I mean by does not work is that the lines execute but the ListBox does
not populate from the callback.

When I used Response.Write from the callback, only the Response statement
and the "I'm back" worked.

When I removed it and then put it back, the original symptoms occurred.

Thanks for your help,

Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top