private async Task <ServiceEndpointCollection> OpenCommunicationListenersAsync(CancellationToken cancellationToken) { ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "Opening communication listeners"); if (this.instanceListeners == null) { this.instanceListeners = this.userServiceInstance.CreateServiceInstanceListeners(); } var endpointsCollection = new ServiceEndpointCollection(); foreach (var entry in this.instanceListeners) { var communicationListener = entry.CreateCommunicationListener(this.serviceContext); this.AddCommunicationListener(communicationListener); var endpointAddress = await communicationListener.OpenAsync(cancellationToken); endpointsCollection.AddEndpoint(entry.Name, endpointAddress); } ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "Opened {0} communication listeners", (this.instanceListeners != null) ? this.instanceListeners.Count() : 0); return(endpointsCollection); }
private async Task <ServiceEndpointCollection> OpenCommunicationListenersAsync(ReplicaRole replicaRole, CancellationToken cancellationToken) { ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "Opening communication listeners - New role : {0}", replicaRole); if (this.replicaListeners == null) { this.replicaListeners = this.userServiceReplica.CreateServiceReplicaListeners(); } var endpointsCollection = new ServiceEndpointCollection(); foreach (var entry in this.replicaListeners) { if (replicaRole == ReplicaRole.Primary || (replicaRole == ReplicaRole.ActiveSecondary && entry.ListenOnSecondary)) { var communicationListener = entry.CreateCommunicationListener(this.serviceContext); this.AddCommunicationListener(communicationListener); var endpointAddress = await communicationListener.OpenAsync(cancellationToken); endpointsCollection.AddEndpoint(entry.Name, endpointAddress); } } ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "Opened {0} communication listeners", (this.replicaListeners != null) ? this.replicaListeners.Count() : 0); return(endpointsCollection); }