Last post May 30, 2013 02:44 PM by SohrabS
May 29, 2013 03:52 PM|SohrabS|LINK
I've been trying out SignalR for a while now and quite like it. I did have a question, however, regarding its implementation in .NET and windows services.
I was able to get SignalR working with .NET (basic console application that connected to server and received messages) but I need to extend it a little bit from here:
What I actually need to do is receive message from connected clients, passing the received message on the server to a windows service that is running on the server, invoke a method in that that service that manipulates the content of the message, generates
a response, returns it back to the server which in turn passes it back to the client that sent the message initially.
I suspect there's a way of going about this but sadly haven't found a sample code/video covering this extensability. any input is much appreciated :)
Edit: I failed to note the second portion of my inquiry which has to do with the type of the message: the message I should like to submit to the SignalR server which in turn invokes the windows service is an xml messgae.
May 30, 2013 04:11 AM|rstrahl|LINK
An easier way to do what you're intendending might be to integrate a SignalR server directly into your Windows Service application. You can host SignalR inside of the service and effectively run the service as a SignalR server. Once you do that you can easily
push messages from the service to all connected clients and you can push messages from any client directly to the server for processing quite easily.
I've recently implemented just such an application and blogged about the overall concept it here:
Regardless of what you do, in order for you to pass data to the backend Windows Service you'll need some sort of messaging mechanism. SignalR used directly can be a good choice for that that essentially allows you to turn any application into a message pump/sink
which is pretty powerful.
There are also ways to do this by going through the Web Server - ie. running SignalR on the Web Server and then messaging in some other way with the service (queues, database messages, semaphores etc.) but this can get complicated very quickly. One of the
beautiful things about SignalR is that you can have a direct link to the service and access the desired functionality directly rather than going thorugh a Web intermediary.
+++ Rick ---
May 30, 2013 01:57 PM|SohrabS|LINK
thank you so much for your detailed response... I somehow was concluding the solution to be along those lines myself.
I will give your link a good read and see where I can go from there; considering how you've gone this route before, you wouldn't mind if along the process I pose further questions to you on the matter would you?
on a side note, I did try to get the self hosting SignalR working on my machine; it works fine on my dev environment (windows 7, IIS express and VS2012, but not on my server which runs 2008R2 and IIS7. Have you had any trouble getting SignalR working on
such environment where there are no web sockets?
I followed some tips on the internet sadly to no avail.
cheers and thank you again,
May 30, 2013 02:30 PM|rstrahl|LINK
If you self host you won't get Web Sockets (at least not from a Web App) because the calls are cross domain. Cross domain calls from a browser can't use WebSockets - SignalR will use long polling in that case.
If you're self hosting you probably need to open the firewall to allow the port that you're using and/or the EXE that is doing the hosting.
May 30, 2013 02:34 PM|SohrabS|LINK
very well, thanks.
Do you know if there's a step by step instruction on setting-up signalr in the way I want to set it up... I read your post and it is quite informative, but I am thinking I'd need to see the steps on how make a windows service work with signalr.
May 30, 2013 02:39 PM|rstrahl|LINK
I'll be posting about this soon, but there's a bit of information available on self hosting with OWIN here:
It's pretty simple. You need to call WebApplication.Start() in your Service's Start() method and Dispose() on Stop(). Not much else you really need to do to get the server up...
May 30, 2013 02:44 PM|SohrabS|LINK
okay, I think I had that link bookmarked but never got round reading it. I am mostly at this point trying to figure this out in the hosted environment where there isn't latest and greatest compoents. SignalR (as for as following their tutorials is concerned)
works like a charm in my dev environment.
looking forward to your post.