SignalR,服务器端方法可以被调用,但客户端的方法都不能,只能在生产环境 [英] SignalR, Server side methods can be called, but client side methods cannot, only in production environment

查看:222
本文介绍了SignalR,服务器端方法可以被调用,但客户端的方法都不能,只能在生产环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地开发了一个枢纽我的通讯在.NET网站发送功能。
服务器程序是由集线器调用,然后发送程序中,我送一个客户端方法来报告进展情况,并最终另一个客户端的方法来报告程序的结局。

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.

我的开发环境是win10与IIS 10,VS2013,.NET 4.5 SignalR 2.2.0。
我可以在我的开发使用的WebSocket,做工精细,但我的生产服务器是赢得2008R2(IIS 7.5),所以我必须用serverSentEvents,对开发工作,以及

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.

下面我的客户code:

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;
});

和我的HUB类:

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());
    }
}

和我Owin启动:

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

在生产环境中,唯一的服务器调用制成,程序工作正常(电子邮件sended),但客户端的方法不会被触发:

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

我的code是precompiled,开发环境包括源$ C ​​$ C和汇编工作,在生产中编译code不起作用。

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

我也试过用 Clients.Client(Context.ConnectionId)而不是 Clients.Caller 以相同的行为。

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

我已阅读<一href=\"http://stackoverflow.com/questions/15071826/signalr-doesnt-call-client-side-functions/15074002\">StackOverflow常见问题articled联系。

I have read the StackOverflow articled linked in faq.

我能做些什么来验证为什么客户端的方法不会被触发?

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

最好的问候

推荐答案

我找到了解决办法!我的生产环境配置在webgarden(多进程)工作的一个应用程序池,因此SignalR doesent正常工作。在此文章的详细程序,以使SQL Server的骨干scaleout配置与SignalR和webgarden工作。这<一个href=\"http://stackoverflow.com/questions/12757525/signalr-lost-messages-if-iis-configure-with-more-than-1-worker-process/12778690#12778690\">stackoverflow引导我找到了解决办法。

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.

这篇关于SignalR,服务器端方法可以被调用,但客户端的方法都不能,只能在生产环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆