SignalR web client without ASP.NET?

梦想的初衷 提交于 2019-12-23 19:47:41

问题


Is it possible to write a WebSocket (SignalR) client without having to embed it in an ASP.NET application hosted on IIS (or other ASP.NET web server)?

For example if I have a Self Hosted SignalR Server with a custom Hub, is it possible (and if so, how) to call it from a "pure" Javascript web client?

In that case we don't have the <script src="~/signalr/hubs" type="text/javascript" /> part with the run-time generated "magic" scripts in the ~/signalr/hubs/ folder.


回答1:


You do not need to have an asp.net application for SignalR to work. You can create a generic html page and still communicate with a SignalR server. You can even utilize silverlight, windows phone or other clients to communicate with a SignalR server, there are plenty that are currently supported and even more that are third party developed (like android, ios, node etc.).

When you say "pure" JavaScript client I'm assuming you mean no third party libraries like JQuery, in this case SignalR currently does not work without JQuery but a client that does not depend on JQuery is in the pipeline (https://github.com/SignalR/SignalR/issues/372).

You can create a Self Hosted server pull down the SignalR by using ASP.NET Owin.

Edit: In order to use self hosted servers you will have to enable cross domain in your application. See the answer to: SignalR: Error during negotiation request: undefined



来源:https://stackoverflow.com/questions/15115799/signalr-web-client-without-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!