这是我的示例中心(.NET):
[HubName("ExampleHub")]
public class ExampleHub : Hub
{
public static void TestFunction()
{
// Code in test function to send to clients
}
}
这里是我的有角度的客户端(另一个组件正在使用此服务,并且正在调用invokeClientEvent()以尝试在我的集线器中调用TestFunction()):
import { signalR, hubConnection, hubProxy } from 'signalr-no-jquery';
@Injectable({
providedIn: 'root'
})
export class ExampleHubService {
protected _hubConnection: hubConnection;
protected _hubProxy: hubProxy;
private _hubName = 'ExampleHub';
private _hubURL = 'myurl' // Just for example
constructor() { }
public invokeClientEvent(message: any): void {
this._hubProxy.invoke('TestFunction');
}
public async startUp(): Promise<void> {
this._hubConnection = new hubConnection(this._hubURL);
await this.initHubProxy();
await this._hubConnection.start()
.done(() => {})
.fail(() => {});
}
private async initHubProxy(): Promise<void> {
this._hubProxy = this._hubConnection.createHubProxy(this._hubName);
}
}
我的连接工作正常,因为我能够从.NET接收到有角度的客户端的消息,但反之则不行。 this._hubProxy.invoke('TestFunction')似乎正在运行,但是集线器TestFunction不会运行/捕获调用吗?我忘记了什么吗?
检查调用时的骆驼外壳。文件here。
public invokeClientEvent(message: any): void {
this._hubProxy.invoke('TestFunction');
}
我应该是这样:
public invokeClientEvent(message: any): void {
this._hubProxy.invoke('testFunction');
}
因为您要调用此名称:
public static void TestFunction()
{
// Code in test function to send to clients
}