我被困在從我的web應用程序顯示來自其他客戶端的響應消息。到目前爲止我做了什麼?爲模型項目上的更改創建信號R回調
的HomeController
private static IHubProxy _hub;
private static HubConnection _connection;
private string url = @"http://server:port/";
private static Model model = new Model();
public ActionResult Login()
{
_connection = new HubConnection(url);
_hub = _connection.CreateHubProxy("ServerHub");
_hub.On<string>("ReturnSendMessage", ShowMessage);
_hub.On<string>("ReturnSignInMessage", ShowMessage);
return View();
}
[HttpPost]
public ActionResult Login(FormCollection collection)
{
model.NickName = collection.Get("NickName");
_connection.Start().Wait();
_hub.Invoke("SignIn", model.NickName, true).Wait();
return RedirectToAction("Chat", "Home");
}
public ActionResult Chat()
{
return View();
}
[HttpPost]
public ActionResult Chat(FormCollection collection)
{
model.Message = collection.Get("Message");
_hub.Invoke("SendMessage", model.NickName, model.Message).Wait();
return View();
}
public ActionResult ChatPartialView()
{
return PartialView("ChatPartialView");
}
視圖 - ChatPartialView
@model DxComWithMe.Models.Model
<div>
<h3>Chat history</h3>
@if (Model != null)
{
foreach (var item in Model.Messages)
{
<strong>@item</strong>
<br>
}
}
</div>
一切工作正常,只要我刷新頁面自己。但我想實現一種機制,在例如Model.Messages已更改。是否有無論如何做,或者我必須依靠這種方法(javascript ...)來實現回調功能:http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc
我認爲是這樣的:/我只是想在我的WPF客戶端。不,只有一個處理請求的服務器(Windows服務)。 – Insight