/// <summary>
        /// Creates a <see cref="T:System.ServiceModel.ServiceHost"/> for a specified type of service with a specific base address.
        /// </summary>
        /// <param name="serviceType">Specifies the type of service to host.</param>
        /// <param name="baseAddresses">The <see cref="T:System.Array"/> of type <see cref="T:System.Uri"/> that contains the base addresses for the service hosted.</param>
        /// <returns>
        /// A <see cref="T:System.ServiceModel.ServiceHost"/> for the type of service specified with a specific base address.
        /// </returns>
        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ServiceHost result = null;

            if (baseAddresses != null
            && baseAddresses.Length > 0
            && HttpContext.Current != null
            && HttpContext.Current.Request != null)
            {
                Uri baseAddress = baseAddresses.First();
                UriBuilder httpUriBuilder = new UriBuilder(baseAddress);
                httpUriBuilder.Scheme = Uri.UriSchemeHttp;
                httpUriBuilder.Port = 80;
                httpUriBuilder.Host = HttpContext.Current.Request.Url.Host;

                UriBuilder httpsUriBuilder = new UriBuilder(baseAddress);
                httpsUriBuilder.Scheme = Uri.UriSchemeHttps;
                httpsUriBuilder.Port = 443;
                httpsUriBuilder.Host = HttpContext.Current.Request.Url.Host;
                result = new ServiceHost(serviceType, httpUriBuilder.Uri, httpsUriBuilder.Uri);
            }
            else
            {
                result = new ServiceHost(serviceType, baseAddresses);
            }

            return result;
        }
 protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
 {
     var pathAndQuery = baseAddresses.First().PathAndQuery;
     var defaultAddress = new Uri(string.Format("http://{0}{1}", ERPStoreApplication.WebSiteSettings.DefaultUrl, pathAndQuery));
     var addresses = new Uri[] { defaultAddress };
     var serviceHost = new UnityServiceHost(serviceType, addresses);
     return serviceHost;
 }
        public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
        {
            IComponentRegistration registration;
            if (constructorString == null) {
                throw new ArgumentNullException("constructorString");
            }

            if (constructorString == string.Empty) {
                throw new ArgumentOutOfRangeException("constructorString");
            }

            if (HostContainer == null) {
                throw new InvalidOperationException();
            }

            // Create work context
            IRunningShellTable runningShellTable = HostContainer.Resolve<IRunningShellTable>();
            ShellSettings shellSettings = runningShellTable.Match(baseAddresses.First().Host, baseAddresses.First().LocalPath);

            ICoeveryHost CoeveryHost = HostContainer.Resolve<ICoeveryHost>();
            ShellContext shellContext = CoeveryHost.GetShellContext(shellSettings);
            IWorkContextAccessor workContextAccessor = shellContext.LifetimeScope.Resolve<IWorkContextAccessor>();
            WorkContext workContext = workContextAccessor.GetContext();
            if (workContext == null) {
                using (IWorkContextScope workContextScope = workContextAccessor.CreateWorkContextScope()) {
                    ILifetimeScope lifetimeScope = workContextScope.Resolve<ILifetimeScope>();
                    registration =  GetRegistration(lifetimeScope, constructorString);
                }
            }
            else {
                ILifetimeScope lifetimeScope = workContext.Resolve<ILifetimeScope>();
                registration = GetRegistration(lifetimeScope, constructorString);
            }

            if (registration == null) {
                throw new InvalidOperationException();
            }

            if (!registration.Activator.LimitType.IsClass) {
                throw new InvalidOperationException();
            }

            return CreateServiceHost(workContextAccessor, registration, registration.Activator.LimitType, baseAddresses);
        }
 /// <summary>
 /// 获Ioc域容器。
 /// </summary>
 /// <param name="constructorString">构造字符串。</param>
 /// <param name="baseAddresses">基地址。</param>
 /// <returns>Ioc容器。</returns>
 protected virtual ILifetimeScope GetLifetimeScope(string constructorString, Uri[] baseAddresses)
 {
     var runningShellTable = HostContainer.Resolve<IRunningShellTable>();
     var shellSettings = runningShellTable.Match(baseAddresses.First().Host, baseAddresses.First().LocalPath);
     var host = HostContainer.Resolve<IHost>();
     var shellContext = host.GetShellContext(shellSettings);
     var workContextAccessor = shellContext.Container;
     return workContextAccessor;
 }