示例#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");
            }
        }
示例#2
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);
        }
示例#4
0
        protected internal override object CreateBehavior()
        {
            var table = RoutingSection.CreateFilterTable(FilterTableName);

            var cfg = new RoutingConfiguration(table, RouteOnHeadersOnly)
            {
                SoapProcessingEnabled = this.SoapProcessingEnabled
            };

            return(new RoutingBehavior(cfg));
        }
        protected internal override object CreateBehavior()
        {
            RoutingConfiguration config;

            if (string.IsNullOrEmpty(this.FilterTableName))
            {
                config = new RoutingConfiguration();
                config.RouteOnHeadersOnly = this.RouteOnHeadersOnly;
            }
            else
            {
                config = new RoutingConfiguration(RoutingSection.CreateFilterTable(this.FilterTableName), this.RouteOnHeadersOnly);
            }

            config.SoapProcessingEnabled = this.SoapProcessingEnabled;
            config.EnsureOrderedDispatch = this.EnsureOrderedDispatch;
            RoutingBehavior behavior = new RoutingBehavior(config);

            //behavior.Impersonation = this.Impersonation;
            return(behavior);
        }