public ReliableServiceBusHost(ServiceBusEndpointInfo sbEndpointInfo, RetryPolicy retryPolicy) { Guard.ArgumentNotNull(sbEndpointInfo, "sbEndpointInfo"); Guard.ArgumentNotNull(retryPolicy, "retryPolicy"); this.sbEndpointInfo = sbEndpointInfo; this.serviceHost = ServiceBusHostFactory.CreateServiceBusHost <T>(sbEndpointInfo); this.retryPolicy = retryPolicy; this.retryPolicy.RetryOccurred += HandleRetryState; AttachEventHandlers(this.serviceHost); }
private ServiceHost CreateFailoverHost() { // If a Service Bus endpoint is known, we can simply ask the factory object to create a new service host. if (this.sbEndpointInfo != null) { return(ServiceBusHostFactory.CreateServiceBusHost <T>(this.sbEndpointInfo)); } else { // Create a new service host depending on whether or not the original service host was hosting a singleton. ServiceHost newHost = ServiceHost.SingletonInstance != null ? new ServiceHost(ServiceHost.SingletonInstance) : new ServiceHost(typeof(T)); // Clone the endpoint information into the new service host. foreach (var endpoint in ServiceHost.Description.Endpoints) { if (!newHost.Description.Endpoints.Contains(endpoint)) { newHost.Description.Endpoints.Add(endpoint); } } // Clone the behavior information into the new service host. foreach (var behavior in ServiceHost.Description.Behaviors) { if (!newHost.Description.Behaviors.Contains(behavior.GetType())) { newHost.Description.Behaviors.Add(behavior); } } // Clone the extension information into the new service host. foreach (var extension in ServiceHost.Extensions) { if (!newHost.Extensions.Contains(extension)) { newHost.Extensions.Add(extension); } } // Clone other service host settings and properties. newHost.Description.Name = ServiceHost.Description.Name; newHost.Description.Namespace = ServiceHost.Description.Namespace; newHost.Description.ConfigurationName = ServiceHost.Description.ConfigurationName; newHost.OpenTimeout = ServiceHost.OpenTimeout; newHost.CloseTimeout = ServiceHost.CloseTimeout; return(newHost); } }