3

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.

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)

Aron
  • 15,464
  • 3
  • 31
  • 64
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
  • 2
    ASMX is a legacy technology, and should not be used for new development. WCF should be used for all new development of web service clients and servers. One hint: Microsoft has retired the [ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads) on MSDN. Finally, ASMX has no capability to notify. – John Saunders May 31 '13 at 00:02
  • Read up on "long polling". In essence: You have a poll request running, which waits on the server until either a timeout (e.g. 30 secs) or an event. Then immediately another poll is started. – Eugen Rieck May 31 '13 at 00:03
  • Take a look at this: [Comet](http://en.wikipedia.org/wiki/Comet_(programming)) – Thomas C. G. de Vilhena May 31 '13 at 00:04
  • I would suggest taking a look at Microsoft's own library for this. [SignalR](http://nuget.org/packages/Microsoft.AspNet.SignalR/) it abstracts out the real time data channel between the server and the client and uses the most efficient transport protocol out of 4 possible technologies (including and not limited to "long polling") – Aron May 31 '13 at 02:22

1 Answers1

6

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.

Taken from asp.net website. The Client 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();
Aron
  • 15,464
  • 3
  • 31
  • 64
  • SignalR is great but you will need to consider backward compatibility with older browsers that do not support WebSockets. –  May 31 '13 at 02:34
  • 2
    @GregDzezinski The nice people at Microsoft did that already. [I will let another SOer explain...](http://stackoverflow.com/a/7874352/1808494) – Aron May 31 '13 at 02:43
  • @GregDzezinski also the OP stated that the client is C# and hence not a browser. – Aron May 31 '13 at 02:47
  • Thanks @Aron. Misplaced comment on my part. I would like to add that SignalR itself is advertised as not support or tested in older browser versions. –  May 31 '13 at 02:53