我在服务总线中遇到问题,它有时会调用客户端方法,有时会中断。
这是我的场景-
当快递员为客户出价时,它会调用服务器端方法,调用成功后通过signalR重定向到客户端函数,并刷新页面并获取新信息(使用烤面包机)。
这是完整的代码-
*服务器端调用
private Notify(ExtraLargeRequest request){
-- Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<NewBidHub>().Clients.All
.broadcastBidNotification(request.Customer.Email, request.Id, "test message");
}
*NewBidHub.cs
public class NewBidHub : Hub
{
public void SendBidNotification(string user, int requestId, string message)
{
// Call the method to notifiy clients.
Clients.All.broadcastBidNotification(user, requestId, message);
}
}
*客户端调用
function createNewBidHub(){
//declaring the hub connection
newBidHub = new Hub('newBidHub', {
//client side methods
listeners: {
'broadcastBidNotification': function (customer, requestId, notification) {
$rootScope.$broadcast('incomingBidNotification', customer, requestId, notification);
}
},
methods: ['SendBidNotification'],
//specify a non default root
rootPath: config.baseServiceName + 'signalr'
});
}
$rootScope.$on('incomingBidNotification', function (fn, customer, requestId, notification) {
toaster.pop("success", "New bid", notification, 5000, 'trustedHtml', onBidNotificationClick, requestId);
if ($location.path().indexOf('/requests/detail') !== -1) {
$rootScope.$broadcast("updateRequestDetails", requestId);
}
});
*启动.cs
public void Configuration(IAppBuilder app)
{
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50);
string connectionString = CloudConfigurationManager.GetSetting("ServiceBusConnectionString");
GlobalHost.DependencyResolver.UseServiceBus(connectionString, "webnotifications-ns");
app.MapSignalR();
}
*版本
服务总线 - 2.1.0.0
jquery-signalR - 2.1.2
你能帮帮我吗!将不胜感激。
提前致谢。