views:

78

answers:

1

In my asp.net application, I am using wcf service to get all the business logic. I am using that service reference in my application to work with that. Now adding that service reference is giving another option Update service reference is giving Generate asynchronous operations. If I check the option and add the service will it generate asynchronous methods for my existing service. If so how do I use the metohd. Let me know the way for that.

Thanks, Hima.

A: 

Check out this article Making Asynchronous Calls to WCF Services from ASP.NET.

Something like this:

protected void Button1_Click(object sender, EventArgs e)
{
    PageAsyncTask pat = new PageAsyncTask(BeginProductRetrieveAsync, EndProductRetrieveAsync, null, null);
    Page.RegisterAsyncTask(pat);       
}

IAsyncResult BeginProductRetrieveAsync(object sender, EventArgs e, AsyncCallback acb, object extraData)
{
    nor = new ProductReference.NorthwindServiceClient();
    return nor.BeginProductList(acb, extraData);
}

void EndProductRetrieveAsync(IAsyncResult ar)
{
    var prods = new List<Products>();
    ListBox1.DataSource = nor.EndProductList(ar);
    ListBox1.DataTextField = "ProductName";
    ListBox1.DataValueField = "ProductID";
    ListBox1.DataBind();
}
alejandrobog
Thanks for your quick reply.. its working fine.. But now in my application I am having more number of pages. Is that means I need to create the ServiceObject in every page..
hima