微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法启动连接:错误并且无法加载资源:SignalR中的net :: ERR_SSL_PROTOCOL_ERROR

如何解决无法启动连接:错误并且无法加载资源:SignalR中的net :: ERR_SSL_PROTOCOL_ERROR

我正在尝试将this example应用于带有.NET Core和Angular的SignalR上,并且我使用了ABP框架,

但是当我开始运行该示例时,浏览器控制台会在错误下方始终为我显示

enter image description here

我的代码详细信息:

这是我的中心

public class HCHub : Hub
    {
    }

下面是我要的服务,我希望集线器与其连接,用户会点击它

[AbpAuthorize]
   public class MyAppService : applicationservice
   {
       private readonly IRepository<MyTable,long> _repository;
       private IHubContext<HCHub> _hub;

       public MyAppService(IRepository<MyTable,long> repository,IHubContext<HCHub> hub)
       {
           _repository = repository;
           _hub = hub;
       }



public async Task Get(long Id,long userRoleFlag)
       {
           try { 
           
           var data = await _repository.GetDbContext().Set<MyTable>()
               .Include(x=>x.list1)
               .ThenInclude(x=>x.list2)
               .ThenInclude(x=>x.message)
               ).ToListAsync();


           var BasicInfo = _hub.Clients.All.SendAsync("transferchartdata",data.Select(x => new MyDto
           {
               name1 = x.name1,Id1 = x.Id1,Id2 = x.Id2,PLACE = x.PLACE,Testvar = x.Testvar,ID4 = x.ID4,ERT = x.ERT,Count = x.Count
           }).OrderByDescending(x => x.Count).ToList());

           }
           catch (Exception ex)
           {
               new UserFriendlyException(ex.InnerException.Message.ToString());
                      }


       }
       }

我已经创建了示例中提到的服务

import { Injectable } from '@angular/core';
import * as signalR from "@aspnet/signalr";

@Injectable({
  providedIn: 'root'
})
export class Signalrservice {

  listofData:Array<any>=[];


private hubConnection: signalR.HubConnection

  public startConnection = () => {
    this.hubConnection = new signalR.HubConnectionBuilder()
                            .withUrl('https://localhost:21021/hchub')
                            .build();

    this.hubConnection
      .start()
      .then(() => console.log('Connection started'))
      .catch(err => console.log('Error while starting connection: ' + err))
  }

  public addTransferChartDataListener = () => {
    
    this.hubConnection.on('transferchartdata',(data) => {
     
      this.listofData = data;
      console.log("$$@#$@#$%@#$%@#$@#$@#$%@#$%@#%$@#$%");
      console.log(data);
      console.log("$$@#$@#$%@#$%@#$%@@#$@#$#$%@#%$@#$%");

    });
  }
}

我已调用集线器服务功能以在Angular组件内部启动连接


async ngOnInit() {
  this.signalrservice.startConnection();
  this.signalrservice.addTransferChartDataListener();  
thisGet(this.gloabalPlace,this.gloabalId); // it is POST Http request
}

然后我在Startup.cs的Configure函数下面添加

    app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<AbpCommonHub>("/signalr"); 
                endpoints.MapHub<MyChatHub>("/signalr-myChatHub");
                endpoints.MapHub<HCHub>("/hchub");
                endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute("defaultWithArea","{area}/{controller=Home}/{action=Index}/{id?}");
            });

  app.UseCors(builder =>
            {
                builder.WithOrigins("http://localhost:4200")
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowCredentials();
            });

解决方法

自托管的一个方面(尽管不是很透明或没有记载)正在SSL下运行自托管SignalR服务。 Windows证书的存储,证书的创建,配置和安装仍然很麻烦,因为Windows中没有提供将端点链接到证书的UI,而且该过程的端到端记录也不够完善。

我认为此链接会有所帮助

Hosting SignalR under SSL

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?