ASMX异步系统InvalidOperationException:当前无法启动异步操作。
创始人
2024-11-11 12:01:10
0

可以使用以下代码来解决这个问题:

[assembly: System.Web.UI.WebResource("MyNamespace.MyControl.js", "text/javascript")]

[ToolboxData("<{0}:MyControl runat=server>")] public class MyControl : WebControl { protected override void OnInit(EventArgs e) { base.OnInit(e);

    if (!this.DesignMode && this.Page != null && this.Page.Header != null)
    {
        string clientScript = @"function MyControl_OnCallbackComplete(result, context) 
                                { 
                                    // Callback code here
                                }";

        ScriptManager.RegisterClientScriptBlock(this.Page, typeof(MyControl), "MyControlScript", clientScript, true);
    }
}

[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public async Task GetSomeDataAsync(string param)
{
    var client = new HttpClient();
    HttpResponseMessage result = await client.GetAsync("http://example.com/api/data");
    var content = await result.Content.ReadAsStringAsync();

    return content;
}

}

这个问题通常是由于您尝试在未绑定Page的ASMX代​​码中尝试启动异步操作造成的。上面的代码示例演示了如何在OnInit事件中使用ScriptManager,以便正确地启动异步操作。

相关内容

热门资讯

透视玄学!pokemomo辅助... 透视玄学!pokemomo辅助软件(透视)开心十三张透视(总是有辅助平台)-哔哩哔哩;1、开心十三张...
透视app!wepoker俱乐... 您好,透视辅助器免费欢聚水鱼这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
此事备受玩家关注!wpk私人局... 此事备受玩家关注!wpk私人局辅助是真的吗(透视)来来拼十辅助(好像是真的辅助插件)-哔哩哔哩1、点...
透视黑科技!wepoker辅助... 透视黑科技!wepoker辅助器软件下载(透视)新九天作必弊系统(本来存在有辅助下载)-哔哩哔哩1、...
出乎意料的是!hhpoker脚... 出乎意料的是!hhpoker脚本(透视)多乐游戏小程序辅助(确实真的是有辅助插件)-哔哩哔哩1、多乐...
透视真的!wepoker能不能... 透视真的!wepoker能不能透视(透视)川南休闲辅助(竟然有辅助平台)-哔哩哔哩一、川南休闲辅助游...
透视透视!大菠萝辅助器(透视)... 透视透视!大菠萝辅助器(透视)杭州都莱到底有没有挂(其实真的是有辅助平台)-哔哩哔哩1.杭州都莱到底...
一直以来!淘宝买wepoker... 一直以来!淘宝买wepoker透视有用吗(透视)创思维激k透视在哪里买(一贯真的是有辅助辅助器)-哔...
据文件显示!wepoker脚本... 据文件显示!wepoker脚本(透视)微信牵手跑有没有挂(好像真的有辅助app)-哔哩哔哩1、许多玩...
透视玄学!wepoker有没有... 透视玄学!wepoker有没有辅助(透视)瑞安玉海楼茶苑辅助器(竟然真的是有辅助app)-哔哩哔哩;...