C# 角2信号机

C# 角2信号机,c#,asp.net,angular,web-services,signalr,C#,Asp.net,Angular,Web Services,Signalr,所以我有一个C#WebApi信号器webservice和一个Angular 2信号器客户端 当来自其他服务可能调用的post方法的新消息传入时,WebService应该更新客户端 [HttpPost] public void NotificationMessage([FromBody]ServiceInformation serviceInformation) { Messages.notificationMessage = service

所以我有一个C#WebApi信号器webservice和一个Angular 2信号器客户端

当来自其他服务可能调用的post方法的新消息传入时,WebService应该更新客户端

[HttpPost]
        public void NotificationMessage([FromBody]ServiceInformation serviceInformation)
        {
            Messages.notificationMessage = serviceInformation;
            notificationMessage.BroadCastNotificationMessage();
        }
另一个服务发布到此方法,此方法在Messages类中设置一个静态变量,然后调用NotificationMessage Hub

public class NotificationMessage : Hub<IClient>
    {
        public void BroadCastNotificationMessage()
        {
            Clients.All.serviceInfoBroadCast(JsonConvert.SerializeObject(Messages.notificationMessage));
        }
    }
问题是: 如果我将invoke调用保留在startConnection方法中,它将从webservice中拉取数据,但它将永远不会再更新。 如果我不使用调用,什么都不会发生。 我不知道为什么Web服务在客户端调用All时不推送信息。我知道post方法是从我自己的内部日志调用的,我知道对象不是空的。 你知道为什么Web服务不推送信息吗?或者为什么客户端不显示它

constructor() {
        this.connectionEstablished = new EventEmitter<Boolean>();
        this.messageReceived = new EventEmitter<ServiceInformationObject>();
        this.connectionExists = false;
        this.connection = $.hubConnection(CONFIGURATION.baseUrls.server);
        this.proxy = this.connection.createHubProxy(this.proxyName);

        this.registerOnServerEvents();
        this.startConnection();
    }

    private startConnection(): void {
        this.connection.start({ jsonp: true, waitForPageLoad: false}).done((data: any) => {
            console.log('Now connected ' + data.transport.name + ', connection ID= ' + data.id);
            this.connectionEstablished.emit(true);
            this.connectionExists = true;
            //this.proxy.invoke('BroadCastNotificationMessage');
        }).fail((error: any) => {
            console.log('Could not connect ' + error);
            this.connectionEstablished.emit(false);
        });
    }

    private registerOnServerEvents(): void {
        this.proxy.on('serviceInfoBroadCast', (data: string) => {
            console.log('received in SignalRService: ' + JSON.stringify(data));
            let jsonData = JSON.parse(data);
            let newData = new ServiceInformationObject(jsonData.ServiceName, jsonData.Message, jsonData.State, jsonData.MachineName, Date.now());
            this.messageReceived.emit(newData);
        });
    }
private subscribeToEvents(): void {
        this._signalRService.connectionEstablished.subscribe(() => {
            this.canSendMessage = true;
        });
        this._signalRService.messageReceived.subscribe((message: ServiceInformationObject) => {
            this._ngZone.run(() => {
                this.testArray.push(message);
            });
        });
    }