Reactjs 信号器正在发送但未接收

Reactjs 信号器正在发送但未接收,reactjs,redux,signalr,signalr.client,asp.net-core-signalr,Reactjs,Redux,Signalr,Signalr.client,Asp.net Core Signalr,我正在用React,Redux前端在我的应用程序中设置SignalR。我能够向我的中心发送消息,但当中心广播消息时,我在控制台中看到以下内容: 警告:找不到名为“UpdateMessages”的客户端方法 下面是我的中间件的样子,它负责位于SignalR hub和我的Redux存储之间。此代码位于其自己的单独文件中: import * as types from '../../actions/actionTypes'; import * as SignalR from '@aspnet/sign

我正在用
React
Redux
前端在我的应用程序中设置
SignalR
。我能够向我的中心发送消息,但当中心广播消息时,我在控制台中看到以下内容:

警告:找不到名为“UpdateMessages”的客户端方法

下面是我的中间件的样子,它负责位于SignalR hub和我的
Redux
存储之间。此代码位于其自己的单独文件中:

import * as types from '../../actions/actionTypes';
import * as SignalR from '@aspnet/signalr-client';

// Get the store
import appStore from '../../store/appStore';

// Declare connection
let connection = new SignalR.HubConnection('http://localhost:49065/im', 'formatType=json&format=text');

export const signalRInvokeMiddleware = (store) => (next) => async (action) => {

    switch (action.type) {
        case types.SIGNALR_SEND_MESSAGE:
            connection.invoke("Send", action.message);
            break;
    }

    return next(action);
}

export const signalRRegisterCommands = (appStore) => {

    connection.on('UpdateMessages', data => {
        debugger;
        appStore.dispatch(updateSignalRMessages(data))
    })

    connection.start();
};

connection.start();
以下是我的商店代码:

import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers/rootReducer';
import { signalRInvokeMiddleware } from '../middleware/signalR/signalRMiddleware';

export default function configureStore(initialState){
    return createStore(
        rootReducer,
        initialState,
        applyMiddleware(thunk, signalRInvokeMiddleware)
    );
}
public class MyChatHub : Hub
{
    public Task Send(string message)
    {
        return Clients.All.InvokeAsync("UpdateMessages", message);
    }
}
这就是我的集线器代码的样子:

import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers/rootReducer';
import { signalRInvokeMiddleware } from '../middleware/signalR/signalRMiddleware';

export default function configureStore(initialState){
    return createStore(
        rootReducer,
        initialState,
        applyMiddleware(thunk, signalRInvokeMiddleware)
    );
}
public class MyChatHub : Hub
{
    public Task Send(string message)
    {
        return Clients.All.InvokeAsync("UpdateMessages", message);
    }
}
更新:我解决了问题。我必须稍微更改一下我的
configureStore()。见下文:

export default function configureStore(initialState){
    const store = createStore(
        rootReducer,
        initialState,
        applyMiddleware(thunk, signalRInvokeMiddleware)
    );

    signalRRegisterCommands(store);

    return store;
}

你在哪里调用SignalRegisterCommands?这就是问题所在。我不得不稍微改变一下我的
configureStore()
方法。现在可以了。