SignalR, Server side methods can be called, but client side methods cannot, only in production environment

不羁岁月 提交于 2019-12-08 03:52:28

问题


I have successfully developed an hub for my newsletter sending function in a .net website. The server procedure is called by the hub, then during the sending routine, I send a client methods to report the progress status, and finally another client method to report ending of the routine.

My dev environment is win10 with IIS 10, VS2013, .NET 4.5 SignalR 2.2.0. I can use websocket in my dev and work fine, but my production server is win 2008r2 (IIS 7.5), so I must use serverSentEvents, working as well on dev.

Here my client code:

$.connection.hub.logging = true;
hubConn = $.connection.newsletterHub;
hubConn.client.addProgress = function (perc, label) {
    UpdateProgress(perc, label)
}
hubConn.client.raiseError = function (message) {
    alert(message);
}
hubConn.client.finishSent = function (D) {
    Sent(D);
}
hubConn.client.notify = function (msg) {
    console.log(msg);
}
$.connection.hub.start({ transport: ['serverSentEvents'] }).done(function () {
    ishubdone = true;
});

And my Hub class:

public class NewsletterHub : Hub, IRequiresSessionState
{
    public void DoSendReal()
    {
        // other stuff
        foreach (string mre in tosend_Manual)
        {
            // other stuff
            Clients.Caller.addProgress(((decimal)cur / (decimal)tc), string.Format("{0}Emails", cur));
        }
        // other stuff
        Clients.Caller.finishSent(R.ToString());
    }
}

And my Owin Startup:

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;

[assembly: OwinStartup(typeof(Shopper.OwinStartup))]

public static partial class Shopper
{
    public class OwinStartup
    {
        public void Configuration(IAppBuilder app)
        {
            var hubConfiguration = new HubConfiguration();
            hubConfiguration.EnableDetailedErrors = true;
            app.MapSignalR();
        }
    }
}

Here is chrome log in development environment, all work fine, server invoked, client methods triggered:

[13:01:18 GMT+0100] SignalR: Client subscribed to hub 'newsletterhub'.
[13:01:18 GMT+0100] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22newsletterhub%22%7D%5D'.
[13:01:18 GMT+0100] SignalR: serverSentEvents transport starting.
[13:01:18 GMT+0100] SignalR: Attempting to connect to SSE endpoint 'http://barzo.topten/signalr/connect?transport=serverSentEvents&clientProtoc…VOMDrrj&connectionData=%5B%7B%22name%22%3A%22newsletterhub%22%7D%5D&tid=10'.
[13:01:18 GMT+0100] SignalR: EventSource connected.
[13:01:18 GMT+0100] SignalR: serverSentEvents transport connected. Initiating start request.
[13:01:18 GMT+0100] SignalR: The start request succeeded. Transitioning to the connected state.
[13:01:18 GMT+0100] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
[13:01:26 GMT+0100] SignalR: Invoking newsletterhub.DoSend
[13:01:30 GMT+0100] SignalR: Triggering client hub event 'addProgress' on hub 'NewsletterHub'.
[13:01:30 GMT+0100] SignalR: Triggering client hub event 'finishSent' on hub 'NewsletterHub'.
[13:01:30 GMT+0100] SignalR: Invoked newsletterhub.DoSend

On production environment, only server invoke is made, the procedure working fine (emails sended), but client method are not triggered:

[12:58:38 GMT+0100] SignalR: Client subscribed to hub 'newsletterhub'.
[12:58:38 GMT+0100] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22newsletterhub%22%7D%5D'.
[12:58:38 GMT+0100] SignalR: serverSentEvents transport starting.
[12:58:38 GMT+0100] SignalR: Attempting to connect to SSE endpoint 'http://www.topten-italia.com/signalr/connect?transport=serverSentEvents&cli…v5PQ4%3D&connectionData=%5B%7B%22name%22%3A%22newsletterhub%22%7D%5D&tid=9'.
[12:58:38 GMT+0100] SignalR: EventSource connected.
[12:58:38 GMT+0100] SignalR: serverSentEvents transport connected. Initiating start request.
[12:58:39 GMT+0100] SignalR: The start request succeeded. Transitioning to the connected state.
[12:58:39 GMT+0100] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
[13:00:14 GMT+0100] SignalR: Invoking newsletterhub.DoSend
[13:00:17 GMT+0100] SignalR: Invoked newsletterhub.DoSend

My code is precompiled, in development environment both source code and compiled work, in production compiled code not work.

I have also tried to use Clients.Client(Context.ConnectionId) instead of Clients.Caller with same behavior.

I have read the StackOverflow articled linked in faq.

What can I do to verify why the client methods are not triggered?

Best regards


回答1:


I found the solution! My production environment has an app pool configured to work in webgarden (multiprocess), so SignalR doesent work properly. In this article the detailed procedure to enable sql server backbone scaleout config to working with SignalR and webgarden. This stackoverflow guided me to find the solution.



来源:https://stackoverflow.com/questions/34310618/signalr-server-side-methods-can-be-called-but-client-side-methods-cannot-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!