I have built a simple chat application using Signalr and Windows Forms, however my app is self-hosted and only works on my localhost address, how can I upload server online on azure and connect my desktop client app to it? I have just started learning Signalr. I have done some research on Google but couldn't find anything that would answer my question.
You only need to publish your signalR Hub as a website, it doesn't matter if you host your website in
The most 'natural' way to host a SignalR Hub is an ASP.Net website, doesn't matter if the website is on azure or not. So you won't find any complex scenario there.
Your chat hub code could look like (code from signalR docs)
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChat
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
}
The only thing you need to do is put the hub in a ASP.NET web Application, even an empty one. Off course you need to add the SignalR nuget package.
In the startup class (required by any OWIN application) you must to call app.MapSignalR
as shown next:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
That's all pretty much.
With the web App created you can host it wherever you want, I suggest you to host the app in an Azure Web App.
This is full/detailed tutorial about how to achieve the steps I told you above:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With