Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法使用WebSocket传输类型与信号集线器连接_Angular_Signalr_Angular6_Azure Service Fabric - Fatal编程技术网

Angular 无法使用WebSocket传输类型与信号集线器连接

Angular 无法使用WebSocket传输类型与信号集线器连接,angular,signalr,angular6,azure-service-fabric,Angular,Signalr,Angular6,Azure Service Fabric,我有一个angular6/材料设计应用程序。我正在尝试使用信号器连接到webservice(Service Fabric+.net core)。但我遇到了以下错误(我在Firefox和Chrome中尝试过): 错误:无法启动传输“WebSockets”:未定义 “错误:无法启动连接:错误:无法初始化任何可用传输。” 在Chrome中,除了前面的两个错误(在示例中,我将令牌替换为xxx)之外,我还有这个错误: WebSocket连接到'wss://localhost:20003/superviso

我有一个angular6/材料设计应用程序。我正在尝试使用信号器连接到webservice(Service Fabric+.net core)。但我遇到了以下错误(我在Firefox和Chrome中尝试过):

错误:无法启动传输“WebSockets”:未定义

“错误:无法启动连接:错误:无法初始化任何可用传输。”

在Chrome中,除了前面的两个错误(在示例中,我将令牌替换为xxx)之外,我还有这个错误:

WebSocket连接到'wss://localhost:20003/supervisor?id=xxxx&access_token=xxxx'失败:HTTP身份验证失败;没有可用的有效凭据

这是我的角度代码:

//Creating Connection
this.hubConnection = new HubConnectionBuilder()
            .withUrl(this.hubUrl, {
                accessTokenFactory: () => {
                  return window.localStorage.getItem('token'); }
                  , transport: (HttpTransportType.WebSockets)})
            .configureLogging(LogLevel.Information)
            .build();   
//Starting Connection 
 this.hubConnection
        .start()
        .then(() => {
            console.log('connection succeeded')
        })
        .catch((e) => {
            console.log('Error while establishing connection  ', e);
        }); 
在我的Web服务中,我在startup.cs中添加了以下代码:

services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
        {
            builder
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin()
                .AllowCredentials();
        }));

//in configure() method
app.UseCors("CorsPolicy");
app.UseWebSockets();
app.UseAuthentication();

请告诉我是否有解决此问题的方法

尝试使用
transport
选项在中添加
skipNegotiation:true
。像这样:
transport:(HttpTransportType.WebSockets),skipNegotiation:true
@R.Richards这解决了我的问题,但是连接将只使用WebSockets,对吗?@C.M.这是真的。通过此设置,不会使用其他传输类型;只有网袋。这在几个应用程序中对我很有效。