此时无法启动异步操作.调用WebService时发生异常? [英] An asynchronous operation cannot be started at this time Exception occurs on calling WebService?

查看:68
本文介绍了此时无法启动异步操作.调用WebService时发生异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC 3项目中,我正在调用Web服务进行登录身份验证.但这会引发异常:

In my ASP.NET MVC 3 project I'm calling a web service for login authentication. But it throws an exception:

异常详细信息:

此时无法启动异步操作.异步操作只能在异步处理程序或模块内或在页面生命周期中的某些事件期间启动.如果在执行页面时发生此异常,请确保该页面被标记为<%@ Page Async ="true"%>.

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" %>.

如何解决此问题?

推荐答案

确保您的Controller方法返回异步任务.

Make sure that your Controller method returns an async Task.

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

基本上,以一种他们认为您仅使用ASP.NET WebForms的方式编写文档,但是显然您也可以在MVC应用程序中使用它,因此需要更新其文档.

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.

这篇关于此时无法启动异步操作.调用WebService时发生异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆