SignalR - "Connection was disconnected before invocation result was received" exception

StackOverflow https://stackoverflow.com/questions/22384068

  •  14-06-2023
  •  | 
  •  

Pregunta

Developing my first SignalR prototype for demo to my company.

Issue I'm running into when attempting to call server function, 'GetChatUsers,' is that when I call the method via JS, I get an exception, 'Connection was disconnected before invocation result was received,' immediately after the server executes the 'Return' of the 'ChatUser. object.

I am using a synchronous call to the method, and I have stepped through the request to insure there is an IEnumerable object being returned. Once the server actually passes off to the client, the client enters the '.fail' method of the method call and the exception is displayed. I'm not sure why this is happening, but I have built the server side and clientside logic similar to how the request for 'GetAllStocks' is built here... http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server

Here is my server code...

using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using UMARepository.DataModels;

namespace UMAChatHub.Service
{
    public class ChatHub : Hub
    {
        public IEnumerable<ChatUsers> GetChatUsers()
        {
            return UMARepository.Service.ChatService.GetChatUsers();
        } 
    }
}

JS/JQuery...

var getChatUsers = function () {
    var umaChatHubProxy = $.connection.chatHub;
    umaChatHubProxy.connection.start().done(function() {
        umaChatHubProxy.server.getChatUsers().done(function(users) {
            $.each(users, function() {
                console(this.firstName);
            });
        }).fail(function(ex) {
            console(ex.message);
        });
    });
};
¿Fue útil?

Solución

The answer finally hit me like a ton of bricks.

The exception, "Connection was disconnected before invocation result was received," occurred because I was attempting to return an Entity Data object, rather than a POCO object.

I fixed this by creating a DTO, and using Automapper to map from the Entity to the DTO object. I returned that object rather than the Entity object and the error no longer occurs.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top