3

I have the following scenario in my project :-

The client makes use of ASP.NET Web API to make HTTP service requests. The Web API sits on top of a couple of WCF services, which in-turn handle all the business logic. The client subscribes to a particular type of event with the Web API. Whenever the Web API receives notifications from the internal WCF services about the occurrence of the event, the Web API in-turn needs to notify (push events to) all the subscribed clients about the events along with their details.

  1. I want to understand the different options which are available for sending asynchronous callbacks from an ASP.NET Web API to the clients.(Currently we are working on a prototype for which the client is a C# Windows Forms application. Later we might opt for ASP.NET MVC4 web application.).

  2. I also want to know which option would be ideal to send asynchronous notifications back to the client when the data that accompanies the notification is of large sizes. In our scenario, the notification data that is sent back from the service may be of large sizes (~ in the range of 5KB - 50 MB).

In our scenario which I described above, can SignalR be used for notifying the c# client from Web API, as and when the Web API receives the callback from the internal WCF services?

Note :- The Web API is currently hosted in a Windows Service and the client is a .NET Windows Forms application.

Any pointers to such code samples or directions on how this can be achieved would be extremely helpful.

Cheers

Kara
  • 5,650
  • 15
  • 48
  • 55
PRN
  • 189
  • 2
  • 8

1 Answers1

2

SignalR is a good fit for the scenario you're describing, so I'd suggest using it for the notifications (especially since you want to start with a WinForms application and later switch to browser clients - with SignalR, you'll be able to connect to the same server-side code).

However, I'd also suggest keeping the notication messages lightweight, so instead of sending the data to the client with them, I'd send a token the client can retrieve the data with from WebAPI (SignalR isn't really ideal for large file transfers).

Lars Höppner
  • 17,834
  • 2
  • 41
  • 67
  • Is there any code samples where both Web API and SignalR are used together? – PRN Jan 05 '14 at 03:47
  • take a look at the links in this question: http://stackoverflow.com/questions/12368800/can-i-incorporate-both-signalr-and-a-restful-api (basically, you can call clients from any class using [GlobalHost.ConnectionManager.GetHubContext()](http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-server#callfromoutsidehub) as long as you know the connection id of the client you want to be calling, and the client can access the WebAPI actions in the usual way, e.g. with an ajax call) – Lars Höppner Jan 05 '14 at 03:54
  • taking a look at [this tutorial](http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-server-broadcast-with-signalr-20) from the docs might also help clarify things – Lars Höppner Jan 05 '14 at 03:59