Problem with Asychronous Web Service Callback

Discussion in 'ASP .Net' started by Frank Mamone, Sep 13, 2004.

  1. Frank Mamone

    Frank Mamone Guest

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


    }

    }

    }
     
    Frank Mamone, Sep 13, 2004
    #1
    1. Advertisements

  2. Please define "does not work". Also, try Response.Write and see if that
    works.
     
    John Saunders, Sep 14, 2004
    #2
    1. Advertisements

  3. Frank Mamone

    Frank Mamone Guest

    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
     
    Frank Mamone, Sep 14, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.