/// <summary> /// Starts the service. /// </summary> private async void Start() { if (!IsStarted) { //Start the TCP server. Logger.LogInformation("Registering service..."); IsStarted = true; _service = await ResonanceServiceFactory.Default.RegisterServiceAsync < DemoCredentials, DemoServiceInformation, DemoAdapterInformation>( new DemoCredentials() { Name = ServiceId }, new DemoServiceInformation() { ServiceId = ServiceId }, HubUrl, SignalRMode.Legacy); Logger.LogInformation("Service started."); _service.ConnectionRequest += _service_ConnectionRequest; _service.Reconnecting += _service_Reconnecting; _service.Error += _service_Error; _service.Reconnected += _service_Reconnected; } }
/// <summary> /// Registers a listening service on the remote hub and starts a service discovery client /// to detect available services. /// </summary> private async void Connect() { if (!IsConnected) { try { IsFree = false; String serviceName = ClientID + " Service"; Logger.LogInformation("Initializing service and discovery..."); Logger.LogInformation($"Registering listening service {serviceName}..."); _service = await ResonanceServiceFactory.Default.RegisterServiceAsync < DemoCredentials, DemoServiceInformation, DemoAdapterInformation>( new DemoCredentials() { Name = serviceName }, new DemoServiceInformation() { ServiceId = ClientID }, HubUrl, SignalRMode.Legacy); _service.ConnectionRequest += OnServiceConnectionRequest; Logger.LogInformation($"Starting service discovery..."); _discoveryClient = new ResonanceSignalRDiscoveryClient <DemoServiceInformation, DemoCredentials>( HubUrl, SignalRMode.Legacy, new DemoCredentials() { Name = ClientID + " Discovery" }); _discoveryClient.ServiceDiscovered += OnServiceDiscovered; _discoveryClient.ServiceLost += OnServiceLost; _discoveryClient.Disconnected += OnDiscoveryError; await _discoveryClient.StartAsync(); IsConnected = true; Logger.LogInformation("Listening service and discovery started."); } catch (Exception ex) { Logger.LogError(ex, ex.Message); } finally { IsFree = true; } } }