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. Advertising

  2. "Frank Mamone" <> wrote in message
    news:...
    > 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.

    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Sep 14, 2004
    #2
    1. Advertising

  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



    "John Saunders" <> wrote in message
    news:...
    > "Frank Mamone" <> wrote in message
    > news:...
    > > 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.
    >
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    Frank Mamone, Sep 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruth
    Replies:
    1
    Views:
    1,405
    Tim Hubberstey
    Jun 26, 2003
  2. yali
    Replies:
    2
    Views:
    732
    anupam
    Aug 31, 2004
  3. SenthilVel

    how to use asychronous calls

    SenthilVel, May 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    406
    SenthilVel
    May 15, 2006
  4. utabintarbo
    Replies:
    8
    Views:
    312
    utabintarbo
    Oct 11, 2006
  5. cmrhema
    Replies:
    0
    Views:
    386
    cmrhema
    Aug 7, 2008
Loading...

Share This Page