Мне нужно получить идентификатор соединения клиента. Я знаю, что вы можете получить его со стороны клиента, используя $.connection.hub.id
. Мне нужно войти в веб-службу, которая обновляет записи в базе данных, в свою очередь отображая обновление на веб-странице. Я новичок в signalR и stackoverflow, поэтому любые советы будут оценены. На моей клиентской веб-странице у меня есть следующее:
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var notify = $.connection.notificationHub;
// Create a function that the hub can call to broadcast messages.
notify.client.broadcastMessage = function (message) {
var encodedMsg = $('<div />').text(message).html();// Html encode display message.
$('#notificationMessageDisplay').append(encodedMsg);// Add the message to the page.
};//end broadcastMessage
// Start the connection.
$.connection.hub.start().done(function () {
$('#btnUpdate').click(function () {
//call showNotification method on hub
notify.server.showNotification($.connection.hub.id, "TEST status");
});
});
});//End Main function
</script>
все работает до тех пор, пока я не хочу обновлять страницу с помощью signalR. Функция show show в моем концентраторе такова:
//hub function
public void showNotification(string connectionId, string newStatus){
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<notificationHub>();
string connection = "Your connection ID is : " + connectionId;//display for testing
string statusUpdate = "The current status of your request is: " + newStatus;//to be displayed
//for testing, you can display the connectionId in the broadcast message
context.Clients.Client(connectionId).broadcastMessage(connection + " " + statusUpdate);
}//end show notification
как я могу отправить connectionid на мой веб-сервис?
Надеюсь, я не пытаюсь сделать что-то невозможное. Спасибо заранее.