Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use SignalR inside Service Stack REST API service

Is it possible to use SignalR inside of a service stack project? We currently are using service stack for our REST web API. We have been pleased overall with its architecture, flexibility, etc. Now we are exploring ways to communicate back with our calling clients using event-driven or push techniques (vs polling for status). I should note that we are currently hosting our API in a windows service, using the AppHostHttpListenerBase (vs hosting inside IIS).

Is it possible to configure a dedicated route that would be passed to SignalR Hub somehow, so these two could live side by side? e.g. http://localhost:8000/api/live/jobs/jobid would hit the SignalR code, but http://localhost:8000/api/jobs/jobid would route to the current DTO based service stack code.

PS - We would like to continue hosting in self host mode, as we like the flexibility of porting to Mono and running on Linux (vs being tied to IIS).

like image 368
JDBet Avatar asked Dec 01 '12 04:12

JDBet


1 Answers

This blog post describes how to use SignalR with a ServiceStack backend: SignalR, Filters and ServiceStack

To summarize, you have to change the ServiceStack Request behavior to Bufferered,

public HelloAppHost()
    : base("Hello Web Services", typeof(HelloService).Assembly)
{
    PreRequestFilters.Add((req,res) => req.UseBufferedStream = true);
}

Then you can add [IncomingHub], [OutgoingHub] attributes to the service methods, like Get() and Post(), etc.

As for OWIN support in ServiceStack, don't hold your breath. This thread shows the opinion of the primary maintainer that there is not a strong case for adding support at this time.

like image 61
Raul Nohea Goodness Avatar answered Nov 11 '22 17:11

Raul Nohea Goodness