Пример #1
0
        /// <summary>
        /// Initializes a new instance of the reliable Windows Azure Service Bus service host that will listen on the specified Service Bus endpoint
        /// and utilize the specified custom retry policy.
        /// </summary>
        /// <param name="sbEndpointInfo">The endpoint details.</param>
        /// <param name="retryPolicy">The custom retry policy that will ensure reliable access to the underlying WCF infrastructure.</param>
        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);
        }
Пример #2
0
        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);
            }
        }