我正在使用SignalR 1.1.2,并且遇到了异步集线器方法的问题。一切正常,我与ForeverFrame运输PC上,但部署在服务器上,并切换到网络套接字运输后,我收到以下错误:SignalR异步操作错误
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" %>.
我的枢纽方法代码:
public async Task<string> getUrl()
{
var url = await MyWebservice.GetMyRoomUrlAsync(Context.User.Identity.Name);
return url;
}
是否支持在SignalR异步方法与网络插座运输?
更新: GetMyRoomUrlAsync代码:
public static Task<string> GetMyRoomUrlAsync(string email)
{
var tcs = new TaskCompletionSource<string>();
var client = new Onif40.VisualStudioGeneratedSoapClient();
client.GetRoomUrlCompleted += (s, e) =>
{
if (e.Error != null)
tcs.TrySetException(e.Error);
else if (e.Cancelled)
tcs.TrySetCanceled();
else
tcs.TrySetResult(e.Result);
};
client.GetRoomUrlAsync(email);
return tcs.Task;
}
后斯蒂芬·克利里澄清我在哪里的问题是,通过重写EAP到APM解决它是微不足道的。
public static Task<string> GetMyRoomUrlAsync(string email)
{
var tcs = new TaskCompletionSource<string>();
var client = new Onif40.VisualStudioGeneratedSoapClient();
client.BeginGetRoomUrl(email, iar =>
{
try
{
tcs.TrySetResult(client.EndGetRoomUrl(iar));
}
catch (Exception e)
{
tcs.TrySetException(e);
}
}, null);
return tcs.Task;
}
不好意思问你一件事。我知道EAP意味着基于事件的异步模式,但APM意味着异步过程管理? – Mou
不,APM意味着异步编程模型(https://msdn.microsoft.com/en-us/library/ms228963.aspx) –
感谢Martin。你的GetMyRoomUrlAsync()函数代码有点难以理解。可能所有的代码都不存在。什么时候GetRoomUrlCompleted()委托会被调用?后来你改变方法,因为在稍后的示例中你使用BeginGetRoomUrl()。 – Mou