背景信息:我正在使用 MVC 4。我在服务器上调用 PersistentConnection SignalR 方法并将其延迟 20 秒,然后再回调到客户端回调方法。在回调方法中,我将 url 设置为 MVC 控制器中的下载方法,以便它启动文件流下载。
问题:这一切在 IIS 7.5 上的本地托管网站上都可以正常工作,但是当我部署到 Azure 云时它非常不一致。我在 Chrome 和 IE 10 上都进行了 10 次测试:在 Chrome 上,40% 的时间下载无法启动,而在 IE 10 上,50% 的时间没有下载。所以发生的事情是 40-50% 的时间没有调用回调方法。我知道是这种情况,因为我在其中放置了 JavaScript 代码以将当前时间打印到页面上,但这也不会触发。以下是 Chrome 和 IE 10 上的网络流量截图:
铬成功:
铬失败:
IE 10 成功:
IE 10 失败:
在我可以使用这个库之前,我真的需要使用 Azure 对客户端的 SignalR 回调 100% 有效。这是 SignalR 的一个已知错误,还是有其他方法可以将此信号器用于 Windows Azure?
这是我的代码:
服务器:
public class MultiFileConnection : PersistentConnection
{
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
System.Threading.Thread.Sleep(20000);
return Connection.Send(connectionId, data);
}
}
客户:
$('#dBtn').click(function () {
var docIds = sceneLayoutService.getSelection();
var href;
var docIdsParam;
if (docIds.length === 0) {
alert("you need to select one");
return false;
}
else if (docIds.length == 1) {
docIdsParam = "docId=" + docIds;
href = window.baseUrl;
var today = new Date();
// Initialize SignalR connection
var connection = $.connection(href + "/multifile");
$("#test-signalr").append("<li>" + today + "</li>");
// SignalR callback method by server
connection.received(function (data) {
today = new Date();
$("#test-signalr").append("<li>" + today + "</li>");
connection.stop();
href = window.baseUrl + '/CloudStorage/Download?' + docIdsParam;
window.location.href = href;
});
// SignalR send data to the server
connection.start()
.done(function () {
connection.send("you need to select one!!");
})
.fail(function () {
alert("Error connecting to signalr realtime service");
});
}
else {
docIdsParam = jQuery.param(docIds.map(function (value) {
return { "name": "docIds", "value": value };
}));
href = window.baseUrl + '/CloudStorage/DownloadZip?' + docIdsParam;
}
return true;
});
包裹清单:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Company.CONNECT.Analytics.eFWrapper" version="1.0.0.1" targetFramework="net40" />
<package id="Company.CONNECT.Analytics.Logging" version="1.0.0.11" targetFramework="net40" />
<package id="Company.CONNECT.Web" version="1.1.0.12" targetFramework="net40" />
<package id="Castle.Core" version="2.5.2" targetFramework="net40" />
<package id="Castle.Core-log4net" version="2.5.2" targetFramework="net40" />
<package id="Castle.Windsor" version="2.5.4" targetFramework="net40" />
<package id="Castle.Windsor-log4net" version="2.5.2" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="EnterpriseLibrary.Common" version="5.0.505.0" targetFramework="net40" />
<package id="EnterpriseLibrary.WindowsAzure.Configuration" version="5.0.1118.2" targetFramework="net40" />
<package id="EntityFramework" version="4.1.10331.0" targetFramework="net40" />
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
<package id="jQuery" version="2.0.2" targetFramework="net40" />
<package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net40" />
<package id="jQuery.Validation" version="1.8.0" targetFramework="net40" />
<package id="jQuery.vsdoc" version="1.5.1" targetFramework="net40" />
<package id="log4net" version="1.2.10" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers" version="1.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers.Core" version="1.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.Core" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.JS" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.Owin" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.5.0" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.5.0" targetFramework="net40" />
<package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net40" />
<package id="Microsoft.Owin.Host.SystemWeb" version="1.0.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net40" />
<package id="Modernizr" version="2.6.2" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="Owin" version="1.0" targetFramework="net40" />
<package id="Pkcs12ProtectedConfigurationProvider" version="1.0.1" targetFramework="net40" />
<package id="RequireJS" version="2.1.8" targetFramework="net40" />
<package id="SevenZipSharp" version="0.64" targetFramework="net40" />
<package id="SlowCheetah" version="2.5.5" targetFramework="net40" />
<package id="System.Spatial" version="5.5.0" targetFramework="net40" />
<package id="System.Web.Providers" version="1.2" targetFramework="net40" />
<package id="Unity" version="2.1.505.2" targetFramework="net40" />
<package id="Unity.Interception" version="2.1.505.2" targetFramework="net40" />
<package id="WebGrease" version="1.1.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="2.0.5.1" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="2.0.6.0" targetFramework="net40" />
</packages>
将不胜感激任何帮助!