asp.net - 从 ASP.Net 以异步方式调用 WCF 会将工作线程返回到 ASP.Net 的线程池吗?

标签 asp.net wcf asynchronous

我正在尝试使我的 ASP.Net 网站更具可扩展性,但不确定在对 WCF 方法的异步调用完成之前接收 Web 请求的 ASP.Net 线程是否返回到线程池或者该线程将等待异步调用完成。

对 WCF 方法的异步调用大约需要 20 到 40 秒才能完成。

编辑 1: 我的代码如下,是我调用异步 WCF 方法的页面代码隐藏部分。 WCF 方法在 WCF 端是异步的,并且也从该页面代码隐藏以异步方式调用。

    protected void Page_Load(object sender, EventArgs e)
    {
        using (ABCService.ServiceClient sc = new ABCService.ServiceClient())
        {
           // List<ABCService.Product> products = sc.GetDocSummary("Vend1", null, false);//this is synchronous call from client
          sc.BeginGetProducts("Vend1",GetProductsCallback, sc);//this is asynchronous call from WCF
        }
    }

    protected void GetProductsCallback(IAsyncResult asyncResult)
    {
        List<ABCService.Product> products = ((ABCService.ServiceClient)asyncResult.AsyncState).EndGetProducts(asyncResult); //this will call the WCF EndGetProducts method
    }

最佳答案

是的,您的线程将返回到线程池,因为您的请求将在 sc.BeginGetProducts 之后完成。 方法 GetProductsCallback 在处理请求时不会有输入。

你应该阅读我对 this question 的回答。这与您的问题类似。

简而言之:要实现您想要的效果,您必须使用异步网页。 如果您使用 .Net 4.5 您应该在 this article 进行掠夺.

关于asp.net - 从 ASP.Net 以异步方式调用 WCF 会将工作线程返回到 ASP.Net 的线程池吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14014567/

相关文章:

asp.net - 将纯 HTML 页面转换为 ASP .NET aspx 页面的最佳 "process"?

c# - 如何从 c# 中的 dob 计算年龄(以年为单位)

c# - ASP.NET MVC 从虚拟路径获取文件

PageRequestManager.getInstance().add_endRequest 的 UpdatePanel 包装器中的 jQuery

wcf - 消息安全异常 : The HTTP request was forbidden with client authentication scheme 'Anonymous' "when accessing credential secured WCF service

javascript - Node JS 中的 promise 圈内的 promise 圈

c# - 宿主在azure上开发wcf服务

c# - WCF 和可能的 Skype 的端口 80 问题

javascript - AngularJS - 循环中的 API 调用 - 获取数组的最大值并设置响应

javascript - 等待 JavaScript 返回 API 结果