简体   繁体   English

从WCF服务调用异步方法

[英]Calling asynchronous methods from wcf service

In my asp.net application, I am using wcf service to get all the business logic. 在我的asp.net应用程序中,我正在使用wcf服务来获取所有业务逻辑。 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 method? 如果可以,该如何使用该方法?

Check out this article Making Asynchronous Calls to WCF Services from ASP.NET . 查看本文,从ASP.NET进行WCF服务的异步调用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM