Exemplo n.º 1
0
        public static MessageFilter CreateFilter(this FilterElement el, RoutingSection sec)
        {
            switch (el.FilterType)
            {
            case FilterType.Action:
                return(new ActionMessageFilter(el.FilterData));

            case FilterType.EndpointAddress:
                return(new EndpointAddressMessageFilter(new EndpointAddress(el.FilterData), false));

            case FilterType.PrefixEndpointAddress:
                return(new PrefixEndpointAddressMessageFilter(new EndpointAddress(el.FilterData), false));

            case FilterType.And:
                var fe1 = (FilterElement)sec.Filters [el.Filter1];
                var fe2 = (FilterElement)sec.Filters [el.Filter2];
                return(new StrictAndMessageFilter(fe1.CreateFilter(sec), fe2.CreateFilter(sec)));

            case FilterType.Custom:
                return((MessageFilter)Activator.CreateInstance(Type.GetType(el.CustomType)));

            case FilterType.EndpointName:
                return(new EndpointNameMessageFilter(el.FilterData));

            case FilterType.MatchAll:
                return(new MatchAllMessageFilter());

            case FilterType.XPath:
                return(new XPathMessageFilter(el.FilterData));

            default:
                throw new ArgumentOutOfRangeException("FilterType");
            }
        }
        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);
        }
 public void Remove(FilterElement element)
 {
     if (!this.IsReadOnly())
     {
         if (element == null)
         {
             throw FxTrace.Exception.ArgumentNull("element");
         }
     }
     BaseRemove(this.GetElementKey(element));
 }
 public void Add(FilterElement element)
 {
     if (!this.IsReadOnly())
     {
         if (element == null)
         {
             throw FxTrace.Exception.ArgumentNull("element");
         }
     }
     BaseAdd(element);
 }
 public void Remove(FilterElement element)
 {
     BaseRemove(element);
 }
 public void Add(FilterElement element)
 {
     BaseAdd(element);
 }
Exemplo n.º 7
0
		public void Remove (FilterElement element)
		{
			BaseRemove (element);
		}
Exemplo n.º 8
0
		public void Add (FilterElement element)
		{
			BaseAdd (element);
		}
Exemplo n.º 9
0
 public void Remove(FilterElement element)
 {
     if (!this.IsReadOnly())
     {
         if (element == null)
         {
             throw FxTrace.Exception.ArgumentNull("element");
         }
     }
     BaseRemove(this.GetElementKey(element));
 }
Exemplo n.º 10
0
 public void Add(FilterElement element)
 {
     if (!this.IsReadOnly())
     {
         if (element == null)
         {
             throw FxTrace.Exception.ArgumentNull("element");
         }
     }
     BaseAdd(element);
 }