asp.net-mvc – 在MVC SignalR服务器和Windows服务SIgnalR客户端
发布时间:2020-12-15 18:58:20 所属栏目:asp.Net 来源:网络整理
导读:我已经知道在这里,我可以在一个普通的 Windows服务中使用SignalR.我想在Windows Server作为SignalR Client和ASP.NET MVC SignalR Server之间进行通信.我用 this hubs guide,说 指定URL的服务器代码 app.MapSignalR("/signalr",new HubConfiguration()); 如果
我已经知道在这里,我可以在一个普通的
Windows服务中使用SignalR.我想在Windows Server作为SignalR Client和ASP.NET MVC SignalR Server之间进行通信.我用
this hubs guide,说
指定URL的服务器代码 app.MapSignalR("/signalr",new HubConfiguration()); 如果我这样做,邮件将在哪里?当您做新的HubConfiguration时,集线器是什么? 它说我可以连接 NET client code that specifies the URL var hubConnection = new HubConnection("http://contoso.com/signalr",useDefaultUrl: false); 我会在我的Windows Server中,但是如果我在服务器上发送文本到http://myserver.com/signalr,我该如何得到它?什么中心? 还有哪里最好把它放在Windows服务中?一个很棒的例子 解决方法
这解决了这个问题
在客户端(Windows服务)上: protected override async void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); try { var hubConnection = new HubConnection("http://www.savitassa.com/signalr",useDefaultUrl: false); IHubProxy alphaProxy = hubConnection.CreateHubProxy("AlphaHub"); await hubConnection.Start(); await alphaProxy.Invoke("Hello","Message from Service"); } catch (Exception ex) { eventLog1.WriteEntry(ex.Message); } } 在服务器上: public class AlphaHub : Hub { public void Hello(string message) { // We got the string from the Windows Service // using SignalR. Now need to send to the clients Clients.All.addNewMessageToPage(message); // Send message to Windows Service } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- SqlServer如何给表添加新的字段以及字段注释
- ASP.NET Core 在 Swagger UI 中显示自定义的 Header或者在u
- asp.net-mvc – 用Moq Mocking HttpContextBase
- .Net Core微服务入门全纪录(七)——IdentityServer4-授权
- asp.net-core – 为什么.net core 2.1 SPA有3个不同的端口?
- asp.net – 如何使用app_GlobalResource或app_LocalResourc
- ASP.NET表单认证在iPad上显示登录页面
- ASP.NET MVC注定要取代Webforms吗?
- asp.net – 如何使用.net用户控件创建Umbraco内容节点?
- asp.net – 是否可以更改web.config而不会终止所有用户会话
推荐文章
站长推荐
热点阅读