我正在使用signalR进行私人消息聊天应用程序,因此,我打电话

时间:2018-09-20 13:27:39

标签: asp.net-mvc signalr signalr-hub signalr.client

Clients.Caller.receiver(re)

响应传递成功,但突然陷入困境,我收到一条错误消息:“不支持使用不由HubPipeline创建的Hub实例”。现在,我无法理解缺少参考的地方。请帮我解决这个问题。

我正在使用以下代码。

public async Task GetAllMessages(int roomid, int fromuserId, int touserId, int index, int pageSize, int broadcastid = 0)
            {
                ResponseModel re = new ResponseModel();
                try
                {
                    var model = new MessageDetailModel
                    {
                        Index = index,
                        PageSize = pageSize,
                        FromUserId = fromuserId,
                        ToUserId = touserId,
                        ChatRoomId = roomid,
                        BroadCastId = broadcastid
                    };
                    MesaageModel totalmessages = new MesaageModel();
                    List<RecentMessage> messages = new List<RecentMessage>();
                    var usermessages = await _userService.GetAllMessages(model);
                    messages.AddRange(usermessages);
                    foreach (var message in messages)
                    {
                        model.BroadCastMessageId = model.BroadCastId == 0 ? 0 : message.BroadCastMessageId;
                        model.ChatRoomMessageId = model.BroadCastId == 0 ? message.ChatRoomMessageId : 0;
                        List<UserDetail> userofseenby = new List<UserDetail>();
                        var users = await _userService.GetMessageSeenBy(model);
                        userofseenby.AddRange(users);
                        message.SeenBy = userofseenby;
                    }

                    // Bhavesh Change
                    totalmessages.Messages = messages;
                    // totalmessages.Messages.AddRange(messages);

                    totalmessages.UnseenMessageCount = await _userService.GetUnSeenCount(messages.FirstOrDefault().ChatRoomId, fromuserId);
                    if (messages.FirstOrDefault().IsBroadCast == true)
                        totalmessages.Users = (List<UserDetail>)await _userService.GetUsersByBroadCastId(messages.FirstOrDefault().BroadCastId);
                    else if (messages.FirstOrDefault().IsGroup == true)
                        totalmessages.Users = (List<UserDetail>)await _userService.GetUsersByChatRoomId((int)messages.FirstOrDefault().ChatRoomId);
                    re.MsgCode = 0; re.MsgText = "Success"; re.MsgType = MessageType.Success;
                    re.ActionCommand = "onAllMessagesReceived";
                    re.SingleObject = totalmessages;
                    Clients.Caller.receiver(re);
                }
                catch (Exception ex)
                {
                    re.ActionCommand = "onAllMessagesReceived";
                    re = ResponseHelper.ErrorResponse(re.ActionCommand, ex.ToString());
                    Clients.Caller.receiver(re);
                }
            }

0 个答案:

没有答案