protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var serviceHost = new LocatorServiceHost(locator, configurator.ImplementedContract, serviceType, baseAddresses); var addresses = baseAddresses; if (allowedSchemes != null) { addresses = baseAddresses.Where(x => allowedSchemes.Contains(x.Scheme)).ToArray(); } configurator.Configure(serviceHost, addresses); return serviceHost; }
public static string LongestMaskedUriBetween(Uri[] uries) { string result = "*"; if (uries.All(u => !u.IsAbsoluteUri)) { string pathPart = string.Empty; string[] paths = uries.Select(u => u.OriginalString).Distinct().ToArray(); string fPart = paths.FirstOrDefault(); if (fPart != null) { pathPart = fPart; foreach (string path in paths.Where(h => h != fPart)) pathPart = LongestMaskedPathBetween(path, pathPart); } result = pathPart; } else { string hostPart = string.Empty; string[] hosts = uries.Where(u => u.IsAbsoluteUri).Select( u => u.Host ).Distinct().ToArray(); string fHost = hosts.FirstOrDefault(); if (fHost != null) { hostPart = fHost; foreach (string host in hosts.Where(h => h != fHost)) hostPart = LongestMaskedStringBetween(host, hostPart); } result = "*" + hostPart + "*" + LongestMaskedUriBetween(uries.Select(u => new Uri(u.PathAndQuery, UriKind.Relative)).ToArray()); } while (result.IndexOf("**") >= 0) result = result.Replace("**", "*"); return string.IsNullOrWhiteSpace(result) ? "*" : result; }