我嘗試在.NET 4下的WebForms應用程序中爲儀表板創建通知。我已下載SignalR 1.2版本(包括.net客戶端和服務器)並準備簡單的通知示例。不幸的是,它不工作,我不明白爲什麼。如果我輸入http://myserver.com/notificationSample/signalr/hubs將出現javascript代理,並且看起來沒問題。SignalR和.NET客戶端無法在ASP.NET WebForms頁面上工作
看看下面的實現,有人看到任何bug嗎?
一個)集線器實施
[HubName("NewMessage")]
public class NewMessageNotifier : Hub
{
public void NotifyDashboards()
{
Clients.All.NewMessageCreated();
}
}
b)中通知呼叫方(服務器)〜/頁/ NotificationCaller.aspx
public partial class NotificationCaller : Page
{
private HubConnection connection;
private IHubProxy proxy;
protected void Page_Load(object sender, EventArgs e)
{
connection = new HubConnection("http://myserver.com/notificationSample");
proxy = connection.CreateHubProxy("NewMessage");
connection.Start().Wait();
}
// it is handler for onclick event on Button control
protected void NotifyDashboard(object sender, EventArgs e)
{
proxy.Invoke("NotifyDashboards").Wait();
}
}
C)儀表板(客戶端,偵聽)〜/頁/控制板。 ASPX
public partial class Dashboard: BasePage
{
private HubConnection connection;
protected void Page_Load(object sender, EventArgs e)
{
connection = new HubConnection("http://myserver.com/notificationSample");
var proxy = connection.CreateHubProxy("NewMessage");
proxy.On("NewMessageCreated", ShowNotification);
connection.Start();
}
private void ShowNotification()
{
ShowAlert("New message added!");
}
}
謝謝,這幫助了我很多,現在我看到了我的誤解。我想澄清一件事。你說,對於網頁我必須使用JS,所以我假設SignalR .NET客戶端可以與WinForms,SilverLight,WP,WPF等技術一起工作,只要你願意,它們可以在內存中存儲對象。它不適用於WebForms,WebApi和ASP MVC。那是對的嗎? – tkestowicz
@tkestowicz這是正確的 – MEYWD
現在一切都足夠清晰。再次感謝。 – tkestowicz