我使用Signalr和Windows Forms构建了一个简单的聊天应用程序,但是我的应用程序是自托管的,只能在我的本地主机地址上运行,如何在Azure上在线上传服务器并将我的桌面客户端应用程序连接到它?我刚开始学习Signalr。我已经对谷歌进行了一些研究,但无法找到能解决我问题的任何内容。
答案 0 :(得分:2)
您只需要将您的signalR Hub发布为网站,如果您在
中托管您的网站并不重要主持SignalR Hub最“自然”的方式是ASP.Net网站,无论网站是否在天蓝色,都无关紧要。所以你不会在那里找到任何复杂的场景。
您的聊天中心代码可能如下(来自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);
}
}
}
您唯一需要做的就是将集线器放在ASP.NET Web应用程序中,即使是空的。当然,您需要添加SignalR nuget包。
在启动类中(任何OWIN应用程序都需要),您必须调用app.MapSignalR
,如下所示:
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();
}
}
}
这就是全部。
创建了Web App后,您可以随时随地托管它,我建议您在Azure Web App中托管该应用程序。
这是关于如何实现我上面告诉你的步骤的完整/详细教程:
答案 1 :(得分:1)
I think the easiest way is to create an Azure Worker Role
and use it to host your server.
Here you can find the documentation that explains how to Host OWIN in an Azure Worker Role.
Hope this helps.
Best of luck!
UPDATE: There seems to be some confusion regarding a self hosted application.
If you have an ASP.NET website that runs on IIS, then the easiest way is through Azure WebApps. Another option is through a Cloud Service, or to create a Virtual Machine on Azure.
But if you indeed have a self hosted OWIN application, then you must have a worker role that can host an OWIN application. In this case, follow the documentation I provided.
Here is how to create a SignalR self hosted application.
So, regarding how you created the SignalR app, you can choose between these methods.
Best of luck!