我今天用了两天这突然停止了任何线索?
毂
public class MyHub1 : Hub
{
private CompanyConnectionSessionMapBLL _namesAdapter = null;
protected CompanyConnectionSessionMapBLL Adapter
{
get
{
if (_namesAdapter == null)
_namesAdapter = new CompanyConnectionSessionMapBLL();
return _namesAdapter;
}
}
public void sendPauseSignalToThePaitentViewScreen(string signal, string companyID, string sessionID)
{
List<CompanyConnectionSessionMap> listOfConnections = Adapter.GetConnectionsByCompanyAndStatus(Convert.ToInt32(companyID), 1);
foreach (CompanyConnectionSessionMap connection in listOfConnections)
{
//Clients.Client(connection.ConnectionID).sendPauseSignal(signal);
Clients.All.sendPauseSignal(signal);
}
}
}
角度控制器
.controller('SessionController', ['$scope', 'DoctorSessionService', '$stateParams', function ($scope, DoctorSessionService, $stateParams) {
$scope.init = function () {
//to load signalr
DoctorSessionService.initialize($stateParams.docId);
}
$scope.init();
$scope.$on('eventPause', function (event, data) {
if (data.data == "Pause") {
$("#dvPause").show();
} else if (data.data == "Resume") {
$("#dvPause").hide();
}
})
}])
Angular Service
.value('$', $)
.factory('DoctorSessionService', ['$q', '$timeout', 'AjaxCallerFactory', '$', '$rootScope', function ($q, $timeout, AjaxCallerFactory, $, $rootScope) {
return {
proxy: null,
test: [],
test1: [],
initialize: function (docId) {
//Getting the connection object
connection = $.hubConnection('http://localhost:60255');
//Creating proxy
this.proxy = connection.createHubProxy('MyHub1');
//Starting connection
connection.start({ jsonp: true })
.done(function () {
console.log('Now connected, connection ID=' + connection.id);
var params = {
companyConnectionSessionMap: {
CompanyID: docId,
ConnectionID: connection.id,
SessionID: 0
}
};
AjaxCallerFactory.ajaxPost("http://localhost:60255/CompanyConnectionSessionMap/SaveCompanyConnectionSessionMap", params);
})
.fail(function () { console.log('Could not Connect!'); });
this.proxy.on('sendPauseSignal', function (message) {
alert(message)
$rootScope.$broadcast('eventPause', {
data: message
});
});
}
}
}])
没有控制台错误,连接正常连接。我使用的是jquery.signalr-2.2.0.js
答案 0 :(得分:0)
这解决了我的问题,proxy.on方法应该在启动连接之前进行
.value('$', $)
.factory('DoctorSessionService', ['$q', '$timeout', 'AjaxCallerFactory', '$', '$rootScope', function ($q, $timeout, AjaxCallerFactory, $, $rootScope) {
return {
proxy: null,
test: [],
test1: [],
initialize: function (docId) {
//Getting the connection object
connection = $.hubConnection('http://localhost:60255');
//Creating proxy
this.proxy = connection.createHubProxy('MyHub1');
this.proxy.on('sendPauseSignal', function (message) {
alert(message)
$rootScope.$broadcast('eventPause', {
data: message
});
});
//Starting connection
connection.start({ jsonp: true })
.done(function () {
console.log('Now connected, connection ID=' + connection.id);
var params = {
companyConnectionSessionMap: {
CompanyID: docId,
ConnectionID: connection.id,
SessionID: 0
}
};
AjaxCallerFactory.ajaxPost("http://localhost:60255/CompanyConnectionSessionMap/SaveCompanyConnectionSessionMap", params);
})
.fail(function () { console.log('Could not Connect!'); });
}
} }])