/// <summary> /// Searches for and returns a service host that is assigned to a contract of the specified type T. /// </summary> /// <typeparam name="T">The type of the service contract.</typeparam> /// <returns>The singleton instance of the service contract implementation hosted by the service host.</returns> public T FindServiceHost <T>() where T : class { ReliableServiceBusHost <object> serviceBusHost = null; foreach (var ep in serviceEndpoints.Values) { if (ep.ServiceHost != null && (serviceBusHost = (ep.ServiceHost as ReliableServiceBusHost <object>)) != null) { if (serviceBusHost.ServiceInstance != null && typeof(T).IsAssignableFrom(serviceBusHost.ServiceInstance.GetType())) { return(serviceBusHost.ServiceInstance as T); } } } return(null); }
public void SimulateServiceHostFaultedState() { string endpointName = "InterRoleCommunication"; ServiceBusEndpointInfo testEndpointInfo = ApplicationConfiguration.Current.ServiceBusSettings.Endpoints[endpointName]; Assert.IsNotNull(testEndpointInfo, "{0} service bus endpoint definition has not been found", endpointName); ReliableServiceBusHost <InterRoleCommunicationService> serviceHost = new ReliableServiceBusHost <InterRoleCommunicationService>(testEndpointInfo); serviceHost.Open(); bool faultEncountered = false; serviceHost.Faulted += (sender, e) => { faultEncountered = true; }; Thread.Sleep(60 * 1000); Assert.IsTrue(faultEncountered); }
public void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { try { if (this.subscriber != null) { this.subscriber.Dispose(); this.subscriber = null; } } catch { // Do not let the code to fail on disposal. } try { if (this.publisher != null) { this.publisher.Dispose(); this.publisher = null; } } catch { // Do not let the code to fail on disposal. } this.disposed = true; } } }