到目前为止,SignalR Hubs 已经在我的开发机器上与 IIS 7.5 中的本地托管网站完美配合。我让客户端在单击事件上向服务器发出信号器调用,然后服务器在将响应发送回客户端上的回调方法之前执行 20 秒的线程延迟。这在所有浏览器中始终有效。但是,当我将应用程序部署到 Windows Azure 云时,SignalR 开始出现这些间歇性问题。具体来说,服务器到达客户端的回调方法似乎有问题。我通过查看 Chrome 开发工具中的网络流量来验证这一点。我可以清楚地看到信号器建立的 POST 连接。它处于“待处理”状态 20 秒,然后在服务器响应时 POST 成功完成。然而,由于某种原因,客户端的回调方法(带有简单的警报消息)并不总是触发。注意:在我的测试中,我注意到一些奇怪的行为,当回调方法没有触发时,我可以通过正常下载文件来触发它(通过使用 href = window.baseUrl + '/CloudStorage/DownloadZip?' ),然后单击触发信号器的按钮。当我在网络流量中观察到这一点时,window.baseUrl BOM 命令会以某种方式触发信号器进行重新连接。将不胜感激任何帮助!/CloudStorage/DownloadZip?'),然后单击触发信号器的按钮。当我在网络流量中观察到这一点时,window.baseUrl BOM 命令会以某种方式触发信号器进行重新连接。将不胜感激任何帮助!/CloudStorage/DownloadZip?'),然后单击触发信号器的按钮。当我在网络流量中观察到这一点时,window.baseUrl BOM 命令会以某种方式触发信号器进行重新连接。将不胜感激任何帮助!
编辑:我使用 IE 10、最新的 Chrome 和最新的 Firefox 进行所有测试。当应用程序在云中时,IE 10 的信号器问题似乎最多,这对我来说有点奇怪,因为这是一个 MS 产品。另外,我使用的是 SignalR 1.1.2 版。
这是我的代码片段:
服务器端:
[HubName("MultiFile")]
public class MultiFile : Hub
{
[HubMethodName("Send")]
public void Send(string DocID)
{
System.Threading.Thread.Sleep(20000);
// Call the addMessage method on caller client
Clients.Caller.addMessage(DocID);
}
}
客户端:
$('#dBtn').click(function () {
var docIds = sceneLayoutService.getSelection();
var href;
var docIdsParam;
if (docIds.length === 0) {
// signalr test code below
// Proxy created on the fly
var test_connection = $.connection.MultiFile;
// Declare a function on the MultiFile hub so the server can invoke it
test_connection.client.addMessage = function (message) {
alert(message);
};
// Start the connection
$.connection.hub.start().done(function () {
// Call the chat method on the server
test_connection.server.Send("you need to select one!");
});
return false;
}
else if (docIds.length == 1) {
docIdsParam = "docId=" + docIds;
href = window.baseUrl + '/CloudStorage/Download?' + docIdsParam;
}
else {
docIdsParam = jQuery.param(docIds.map(function (value) {
//var parts = value.match(/[e[B|b]:\/\/[^\/]*\/\d*\/(\d*)/);
//return { "name": "docIds", "value": parts[1] };
return { "name": "docIds", "value": value };
}));
href = window.baseUrl + '/CloudStorage/DownloadZip?' + docIdsParam;
}
$(this).attr('href', href);
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>