Angular SignalR Error during negotiation request

浪尽此生 提交于 2019-12-02 13:51:28

SignalR do not generate proxy classes for you.

You have just to configure SignalR using MapSignalR() :

    public void Configuration(IAppBuilder app)
    {
        var config = new HttpConfiguration();

        var settings = new JsonSerializerSettings();
        settings.ContractResolver = new SignalRContractResolver();
        var serializer = JsonSerializer.Create(settings);
        GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);

        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR();
    }

Add HubName attribute above your hub class :

[HubName("ServerRefreshHub")]
public class ServerRefreshHub : Hub

Don't forget to specify your hubConnection url when declaring hubConnection and specify your hubName when creating your proxy.

this.connection = $.hubConnection();
this.connection.url = "http://localhost:58965/signalr";
this.proxy = this.connection.createHubProxy('ServerRefreshHub');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!