Я не могу вызвать свой метод-концентратор в моем asp. net базовом бэкэнде,
, это мой комментарий в концентраторе:
import 'package:signalr_client/signalr_client.dart';
import 'package:logging/logging.dart';
import 'package:xperience/models/global.dart';
final serverUrl = "http://" + base + ":8070/CommentHub/";
final hubConnection = HubConnectionBuilder().withUrl(serverUrl).build();
class HubService {
static final hubProtLogger = Logger("SignalR - hub");
static final transportProtLogger = Logger("SignalR - transport");
static final connectionOptions = HttpConnectionOptions;
static final httpOptions = new HttpConnectionOptions(logger: transportProtLogger);
final hubConnection = HubConnectionBuilder().withUrl(serverUrl, options: h
httpOptions).configureLogging(hubProtLogger).build();
Future addUser(String UserId,String PostId) async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
hubConnection.start().then((result) async {
final result=await hubConnection.invoke("AddUser",args:<Object>[UserId,PostId]);
print(result);
});
}
Future removeUser() async {
final result = await hubConnection.invoke("RemoveUser",args: <Object>[]);
print(result);
hubConnection.stop();
}
}
Это мой CommentHub. класс cs в asp. net core:
using System;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Xperience.Data.Entities.Posts;
namespace Xperience.Hub
{
public class CommentHub : Microsoft.AspNetCore.SignalR.Hub
{
public static List<Connection> Connections = new List<Connection>();
public void AddUser(string UserId,string PostId) {
Connections.Add(new Connection
{
ConnectionId = Context.ConnectionId,
UserId = UserId,
PostId = int.Parse(PostId)
});
}
public void RemoveUser() {
var user = Connections.Find(x => x.ConnectionId == Context.ConnectionId);
Connections.Remove(user);
}
}
public class Connection {
public string ConnectionId { get; set; }
public string UserId { get; set; }
public int PostId { get; set; }
}
}
Я хочу вызывать AddUser и RemoveUser всякий раз, когда мой пользователь входит и покидает страницу, но всякий раз, когда я вызываю addUser, я получаю эту ошибку:
**[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid argument(s)
and Sometimes : 'GeneralError' is not a subtype of type 'Error' in type cast**
Хотя соединение успешно установлено:
HTTP send: url 'http://ipAddress:8070/CommentHub/?id=XAekJZiTdIqswThHnPHWRQ', method: 'POST' content: '{"type":6}'
I/flutter (17474): FINEST: 2020-04-15 15:54:48.840894: (SSE transport) request complete. Response status: 200.