Client doesn't make a connection to the SignalR server

巧了我就是萌 提交于 2019-12-13 04:07:38

问题


I'm trying to implement SignalR into my application. To start things of I just started with something very basic, but for some reason I'm getting an error the whole time. Pease could you have a look at my code and see where I'm doing something wrong. Thanks in advance.

Starup Code

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(CdvPortal.Startup))]
namespace CdvPortal
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            app.MapSignalR();
        }
    }
}

Hub Code

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace CdvPortal.Hubs
{

    public class ReservationsHub : Hub
    {
        public void NewReservations()
        {
            Clients.All.NewReservation("hey this works");
        }
    }
}

Client side code

<script src="~/Scripts/jquery-2.1.3.js"></script>
        <script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
        @*<script src="~/Signalr/hubs"></script>*@
        <script type="text/javascript">

            (function () {
                var connection = $.hubConnection();
                var hub = connection.createHubProxy('reservationsHub')
                hub.on('NewReservation', function (message) {
                    alert(message);
                });

                connection.start().done(function(){
                    hub.invoke('NewReservations')
                });                    
            }());

来源:https://stackoverflow.com/questions/29945911/client-doesnt-make-a-connection-to-the-signalr-server

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