You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中使用SignalR.Client遇未实现错误:HoloLens2 UWP项目HTTPS重定向问题

HoloLens 2 UWP项目SignalR连接异常问题

异常场景

当.NET 6 Web API服务器启用HTTPS重定向(app.UseHttpsRedirection();),且Unity端通过ServerCertificateCustomValidationCallback忽略SSL证书时,SignalR连接失败。

Unity端相关代码

private void Start()
{
    _hubConnection = new HubConnectionBuilder()
    .WithUrl("http://192.168.178.41:5266/Signaler", (opts) =>
    {
        opts.HttpMessageHandlerFactory = (message) =>
        {
             // 绕过SSL证书验证
             if (message is HttpClientHandler clientHandler)
             {
                  clientHandler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
             }
            return message;
     };})
     .WithAutomaticReconnect()
     .Build();

     Connect();
}

private async Task Connect()
{
   _hubConnection.On<string>("SomeKey", (key) =>
   {
       Debug.Log($"New Key: {key}");
   });

   try
   {
       await _hubConnection.StartAsync(tokenSource.Token);
   }
   catch (Exception ex)
   { ... }
}

报错信息(精简版)

System.NotImplementedException: The method or operation is not implemented.
  at XXXXX.Network.MySignalRClient+<>c.<Start>b__1_1 (System.Net.Http.HttpMessageHandler message) [0x0000a] in D:\Repositories\XXXXX\Unity\XXXXX\Assets\Scripts\NetworkClients\MySignalRClient.cs:31 
  at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.CreateHttpClient () [0x00118] in <d4f814eb48994df3870fe7c8338cc73a>:0 
  at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection..ctor (Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions httpConnectionOptions, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) [0x0009f] in <d4f814eb48994df3870fe7c8338cc73a>:0 

报错行对应代码中ServerCertificateCustomValidationCallback的赋值行

正常场景

关闭服务器HTTPS重定向,并移除Unity端证书忽略代码后,SignalR可正常连接:

_hubConnection = new HubConnectionBuilder()
    .WithUrl("http://192.168.178.41:5266/Signaler")
    .WithAutomaticReconnect()
    .Build();

预期行为

无需在服务器端关闭HTTPS重定向,仅通过Unity端的证书验证回调即可正常建立SignalR连接。

环境信息

  • SignalR客户端版本:Microsoft.AspNetCore.SignalR.Client.7.0.0
  • 基于.NET Standard 2.0及对应依赖库

补充说明

在Visual Studio中创建的空.NET 6项目使用相同的证书忽略代码可正常连接,推测问题出在.NET Standard 2.0相关DLL上。

内容的提问来源于stack exchange,提问作者Perazim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 08:08:31