SignalR挂起外部模型类

时间:2015-07-28 14:51:28

标签: c# asp.net model signalr

我有一个非常简单的SignalR集线器,每当我尝试将模型类移动到类库时,就会注意到集线器上的挂起。每当我在ASP.net项目中保留Model类时它工作正常并从服务器检索对象但是一旦我将Model类移动到类库(以便跨项目重用),来自客户端(js端)的SignalR调用挂起。我可以看到请求通过设置断点进入集线器,但之后它不会在客户端返回..这里有任何线索吗?

我已在客户端启用了日志记录:

[16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Client subscribed to hub 'myHubhub'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22myHubhub%22%7D%5D'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: serverSentEvents transport starting.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:1275/signalr/connect?transport=serverSentEvents&clientProt…VWFxHpWoC0T&connectionData=%5B%7B%22name%22%3A%22myHubhub%22%7D%5D&tid=6'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: EventSource connected.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: serverSentEvents transport connected. Initiating start request.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: The start request succeeded. Transitioning to the connected state.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Invoking myHubhub.RetrieveMyObjects

服务器端集线器方法:

public IEnumerable<MyModel> RetrieveMyObjects()
{
    using (DatabaseContext dbContext = new DatabaseContext())
    {
        Debug.WriteLine("RetrieveMyObjects()");
        List<MyModel> objs = dbContext.MyObjects.ToList();
        return objs;
    }
}

客户端调用:

@section scripts
{        
    <script>       
        $(function () {           
            // Reference the auto-generated proxy for the hub.
            var chat = $.connection.myHub;
            // Create a function that the hub can call back to display messages.
            chat.client.addNewMessageToPage = function (name, message) {
                // Add the message to the page.
                $('#discussion').append('<li><strong>' + htmlEncode(name)
                    + '</strong>: ' + htmlEncode(message) + '</li>');
            };
            $.connection.hub.logging = true;
            // Start the connection.
            $.connection.hub.start().done(function () {

                // Call the Send method on the hub.
                chat.server.retrieveMyObjects().done(function (result) {
                    console.log("yep");
                    //Process logic
                }).fail(function (err) {
                    console.log('Could not Connect! ' + err);
                });
            });
        });

    </script>
}

1 个答案:

答案 0 :(得分:1)

嗯,我开始剥离我的模型并找到了aswer。我有一个枚举属性标有&#34; [JsonConverter(typeof(StringEnumConverter))]&#34;将枚举序列化为字符串值。当模型在外部类lib中时,这显然会破坏一些东西?

修改 问题:外部类lib引用了Netwonsoft.Json 7.0.0,我的ASP.NET项目重新引用了6.0.4版本。一旦我在类lib上将Netwonsoft.Json降级到6.0.4,一切都按预期工作。