从ASP.Net服务器推送通知 [英] Push notification from an ASP.Net server

查看:147
本文介绍了从ASP.Net服务器推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有执行某些操作的web服务。当事件发生时,我会想,通知客户端。我的问题是,我能够从客户端其他方式连接到服务器,但不是因为客户端恰好是一个NAT(路由器)的后面。目前,我做的每一分钟来检查通知的请求。这将是很好,如果我能有一个技术,我可以在客户更快的通知,而无需让这么多不必要的请求。

I have a web service that performs some operations. When an event occurs I will like to notify the clients. The problem that I have is that I am able to connect from the client to the server but not the other way around because clients happen to be behind a NAT (router). Currently I am making a request every minute to check for notifications. It would be nice if I can have a technique where I could notify the clients faster without having to make so many unnecessary request.

请注意:
客户端是一个C#控制台应用程序和服务器是一个asp.net网站。

Note: The client is a c# console application and the server is a asp.net website.

(注意,如果事件在服务器上发生了,我会想通知所有客户端)

(note if an event happens on the server I will like to notify all clients)

推荐答案

使用SignalR。这是微软对抽象出实时服务器,客户端连接新的图书馆,如果你的设置允许,它支持新的WebSockets协议。

Use SignalR. This is Microsoft's new library for abstracting out real time server-client connections and if your setup allows it, it supports the new WebSockets protocol.

从asp.net网站拍摄。客户code

var hubConnection = new HubConnection("http://www.contoso.com/");
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("StockTickerHub");
stockTickerHubProxy.On<Stock>("UpdateStockPrice", 
    stock => Console.WriteLine("Stock update for {0} new price {1}", stock.Symbol, stock.Price));
await hubConnection.Start();

这篇关于从ASP.Net服务器推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆