简体   繁体   English

此时无法启动异步操作 调用 WebService 时发生异常?

[英]An asynchronous operation cannot be started at this time Exception occurs on calling WebService?

In my ASP.NET MVC 3 project I'm calling a web service for login authentication.在我的 ASP.NET MVC 3 项目中,我正在调用 Web 服务进行登录身份验证。 But it throws an exception:但它抛出一个异常:

异步异常

Exception Details:异常详情:

An asynchronous operation cannot be started at this time.此时无法启动异步操作。 Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle.异步操作只能在异步处理程序或模块内或在页面生命周期中的某些事件期间启动。 If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.如果在执行 Page 时发生此异常,请确保将 Page 标记为 <%@ Page Async="true" %>。

How to fix this issue?如何解决这个问题?

Make sure that your Controller method returns an async Task.确保您的 Controller 方法返回一个异步任务。

public class ServiceController : Controller 
{
    public async Task<ActionResult> Index()
    {       
        var service = new Service();
        await service.CallMethodAsync();    
        return View();
    }
}

Basically, the documentation is written in a way where they believe you are only using ASP.NET WebForms, however obviously you can use this in MVC applications too, so their documentation needs to be updated.基本上,文档的编写方式他们认为您只使用 ASP.NET WebForms,但显然您也可以在 MVC 应用程序中使用它,因此他们的文档需要更新。

您正在调用 ASYNC 方法,因此您必须在页面声明 <%@ Page .....%> 中添加 Async="true"。

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

相关问题 调用FatSecret Sharp API时,此时无法启动异步操作 - An asynchronous operation cannot be started at this time when calling FatSecret Sharp API 目前无法启动异步操作 - Asynchronous operation cannot be started at this time 此时无法启动异步操作 - An asynchronous operation cannot be started at this time C#目前无法启动异步操作。 - C# An asynchronous operation cannot be started at this time. ASMX async System.InvalidOperationException:此时无法启动异步操作 - ASMX async System.InvalidOperationException: An asynchronous operation cannot be started at this time 在C#中调用存储过程后,发生超时异常 - Time out exception occurs after calling a Stored Procedure in C# 在先前的异步操作完成之前,在该上下文上开始第二操作 - A second operation started on this context before a previous asynchronous operation completed 在前一个异步操作完成之前在此上下文上启动了第二个操作 - Second operation started on this context before a previous asynchronous operation completed UOW-在先前的异步操作完成之前,第二个操作在此上下文上开始 - UOW - A second operation started on this context before a previous asynchronous operation completed 调用Web服务时出现未知异常 - Unknown exception when calling a webservice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM