lundi 4 septembre 2017

SignalR: Value cannot be null. Parameter name: s, when sending to specific group

I'm trying to implement simple chat using SignalR and I'm facing the problem with sending message to all Clients.

I'm using Web API and SPA in React so server side and client are separated.

My server code:

[Authorize]
public class ChatHub : Hub
{
    public void Send(string name, string message)
    {
        Clients.All.addMessage(name, message);
    }
}

My client code:

   componentDidMount() {
    this.state = {
        messages: [],
        connection: connectionHub,
        hub: connectionHub.createHubProxy('chatHub')
    };
    this.props.getMessages(this.props.match.params.id);
    let chat = this.state.hub;
    let self = this;

    chat.on('addMessage', function (sender, text) {
    }.bind(this));
    let token = cookie.load('token');
    this.state.connection.qs = { 'access_token' : token };
    this.state.connection.start({ transport: 'longPolling' })
        .done(function () {
            chat.invoke('send', 'Test', "init");
        })
        .fail(function () { console.log('Could not connect'); });

}

Configuration:

    public void Configuration(IAppBuilder app)
    {
        app.Map("/signalr", map =>
        {
            map.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Active,
                AllowedAudiences = new[] { AudienceId },
                IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                {
                    new SymmetricKeyIssuerSecurityTokenProvider(Issuer,Encoding.ASCII.GetBytes(ApiSecretKey))
                },
                Provider = new QueryStringOAuthBearerProvider()
            });

            map.UseCors(CorsOptions.AllowAll);
            var hubConfiguration = new HubConfiguration
            {
               EnableJSONP = true,
            };
            map.RunSignalR(hubConfiguration);

        });

        ConfigureAuth(app);
    }

The method Send is calling correctly I catch it in debug but addMessage doest come to client.

In console i got an error.

enter image description here




Aucun commentaire:

Enregistrer un commentaire