public static MessageFilterTable <IEnumerable <ServiceEndpoint> > CreateFilterTable(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw FxTrace.Exception.ArgumentNullOrEmpty("name");
            }

            RoutingSection routingSection = (RoutingSection)ConfigurationManager.GetSection("system.serviceModel/routing");

            if (routingSection == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.RoutingSectionNotFound));
            }

            FilterTableEntryCollection routingTableElement = routingSection.FilterTables[name];

            if (routingTableElement == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.RoutingTableNotFound(name)));
            }
            XmlNamespaceManager xmlNamespaces = new XPathMessageContext();

            foreach (NamespaceElement nsElement in routingSection.NamespaceTable)
            {
                xmlNamespaces.AddNamespace(nsElement.Prefix, nsElement.Namespace);
            }

            FilterElementCollection filterElements = routingSection.Filters;
            MessageFilterTable <IEnumerable <ServiceEndpoint> > routingTable = new MessageFilterTable <IEnumerable <ServiceEndpoint> >();

            foreach (FilterTableEntryElement entry in routingTableElement)
            {
                FilterElement filterElement = filterElements[entry.FilterName];
                if (filterElement == null)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.FilterElementNotFound(entry.FilterName)));
                }
                MessageFilter filter = filterElement.CreateFilter(xmlNamespaces, filterElements);
                //retreive alternate service endpoints
                IList <ServiceEndpoint> endpoints = new List <ServiceEndpoint>();
                if (!string.IsNullOrEmpty(entry.BackupList))
                {
                    BackupEndpointCollection alternateEndpointListElement = routingSection.BackupLists[entry.BackupList];
                    if (alternateEndpointListElement == null)
                    {
                        throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.BackupListNotFound(entry.BackupList)));
                    }
                    endpoints = alternateEndpointListElement.CreateAlternateEndpoints();
                }
                //add first endpoint to beginning of list
                endpoints.Insert(0, ClientEndpointLoader.LoadEndpoint(entry.EndpointName));
                routingTable.Add(filter, endpoints, entry.Priority);
            }

            return(routingTable);
        }
        internal MessageFilter CreateFilter(XmlNamespaceManager xmlNamespaces, FilterElementCollection filters)
        {
            MessageFilter filter;

            switch (this.FilterType)
            {
            case FilterType.Action:
                filter = new ActionMessageFilter(this.FilterData);
                break;

            case FilterType.EndpointAddress:
                filter = new EndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                break;

            case FilterType.PrefixEndpointAddress:
                filter = new PrefixEndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                break;

            case FilterType.And:
                MessageFilter filter1 = filters[this.Filter1].CreateFilter(xmlNamespaces, filters);
                MessageFilter filter2 = filters[this.Filter2].CreateFilter(xmlNamespaces, filters);
                filter = new StrictAndMessageFilter(filter1, filter2);
                break;

            case FilterType.EndpointName:
                filter = new EndpointNameMessageFilter(this.FilterData);
                break;

            case FilterType.MatchAll:
                filter = new MatchAllMessageFilter();
                break;

            case FilterType.Custom:
                filter = CreateCustomFilter(this.CustomType, this.FilterData);
                break;

            case FilterType.XPath:
                filter = new XPathMessageFilter(this.FilterData, xmlNamespaces);
                break;

            default:
                // We can't really ever get here because set_FilterType performs validation.
                throw FxTrace.Exception.AsError(new InvalidOperationException());
            }
            return(filter);
        }
        internal MessageFilter CreateFilter(XmlNamespaceManager xmlNamespaces, FilterElementCollection filters)
        {
            MessageFilter filter;

            switch (this.FilterType)
            {
                case FilterType.Action:
                    filter = new ActionMessageFilter(this.FilterData);
                    break;
                case FilterType.EndpointAddress:
                    filter = new EndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                    break;
                case FilterType.PrefixEndpointAddress:
                    filter = new PrefixEndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                    break;
                case FilterType.And:
                    MessageFilter filter1 = filters[this.Filter1].CreateFilter(xmlNamespaces, filters);
                    MessageFilter filter2 = filters[this.Filter2].CreateFilter(xmlNamespaces, filters);
                    filter = new StrictAndMessageFilter(filter1, filter2);
                    break;
                case FilterType.EndpointName:
                    filter = new EndpointNameMessageFilter(this.FilterData);
                    break;
                case FilterType.MatchAll:
                    filter = new MatchAllMessageFilter();
                    break;
                case FilterType.Custom:
                    filter = CreateCustomFilter(this.CustomType, this.FilterData);
                    break;
                case FilterType.XPath:
                    filter = new XPathMessageFilter(this.FilterData, xmlNamespaces);
                    break;
                default:
                    // We can't really ever get here because set_FilterType performs validation.
                    throw FxTrace.Exception.AsError(new InvalidOperationException());
            }
            return filter;
        }