HNeukermans / ng2-signalr

angular2 - asp.net signalr library
MIT License
173 stars 81 forks source link

Invoke with parameters #175

Closed gregchak closed 3 years ago

gregchak commented 3 years ago

I'm having trouble invoking a Hub method that has parameters. I can invoke a Hub method without parameters successfully, but as soon a I introduce parameters I get these errors in the log

SignalR: hub.method failed to execute. Error: There was an error invoking Hub method 'hub.method'.
Invoking 'meethod' failed. Rejecting promise...
Promise rejected.
core.js:6014 ERROR Error: Uncaught (in promise): Error: There was an error invoking Hub method 'hub.method'.

My code is simple:


this.connection.invoke('method', { param1: 'test' })
      .then((message) => {
        console.debug('method message', message);
      });```
gregchak commented 3 years ago

Turns out that they are not named parameters. The samples I had looked at made it seem this way. Not seeing the Hub code I didn't see the translation. In the way I was passing param1 in my code, it would have translated to an object with a property named param1. In reality I should have been calling it like

this.connection.invoke('method', 'test');

Parameter are not named. The call only looks at the method name and parameter types when invoking.