2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Configuration;
6 using System.ServiceModel;
7 using System.ServiceModel.Channels;
8 using System.ServiceModel.Configuration;
9 using System.ServiceModel.Description;
10 using System.ServiceModel.Dispatcher;
12 namespace System.ServiceModel.Routing.Configuration
14 static class RoutingConfigurationExtension
16 public static ServiceEndpoint CreateEndpoint (this ChannelEndpointElement el)
19 throw new NotImplementedException ();
22 public static MessageFilter CreateFilter (this FilterElement el, RoutingSection sec)
24 switch (el.FilterType) {
25 case FilterType.Action:
26 return new ActionMessageFilter (el.FilterData);
27 case FilterType.EndpointAddress:
28 return new EndpointAddressMessageFilter (new EndpointAddress (el.FilterData), false);
29 case FilterType.PrefixEndpointAddress:
30 return new PrefixEndpointAddressMessageFilter (new EndpointAddress (el.FilterData), false);
32 var fe1 = (FilterElement) sec.Filters [el.Filter1];
33 var fe2 = (FilterElement) sec.Filters [el.Filter2];
34 return new StrictAndMessageFilter (fe1.CreateFilter (sec), fe2.CreateFilter (sec));
35 case FilterType.Custom:
36 return (MessageFilter) Activator.CreateInstance (Type.GetType (el.CustomType));
37 case FilterType.EndpointName:
38 return new EndpointNameMessageFilter (el.FilterData);
39 case FilterType.MatchAll:
40 return new MatchAllMessageFilter ();
41 case FilterType.XPath:
42 return new XPathMessageFilter (el.FilterData);
44 throw new ArgumentOutOfRangeException ("FilterType");
49 public class RoutingSection : ConfigurationSection
51 static ServiceModelSectionGroup wcfRootSection = ConfigurationManager.GetSection ("system.serviceModel") as ServiceModelSectionGroup;
53 static ServiceEndpoint CreateServiceEndpoint (string name)
55 // FIXME: might be service endpoints.
56 var endpoints = wcfRootSection.Client.Endpoints;
57 return ((ChannelEndpointElement) endpoints [name]).CreateEndpoint ();
61 public static MessageFilterTable<IEnumerable<ServiceEndpoint>> CreateFilterTable (string name)
63 var sec = (RoutingSection) ConfigurationManager.GetSection ("system.serviceModel/routing");
65 var filters = new Dictionary<string,MessageFilter> ();
66 var table = new MessageFilterTable<IEnumerable<ServiceEndpoint>> ();
67 var ftec = (FilterTableEntryCollection) sec.FilterTables [name];
68 foreach (FilterTableEntryElement fte in ftec) {
70 if (filters.TryGetValue (fte.FilterName, out filter)) {
71 var filterElement = (FilterElement) sec.Filters [fte.FilterName];
72 filter = filterElement.CreateFilter (sec);
74 table.Add (filter, new List<ServiceEndpoint> (), fte.Priority);
75 var list = (List<ServiceEndpoint>) table [filter];
76 list.Add (CreateServiceEndpoint (fte.EndpointName));
77 var bec = (BackupEndpointCollection) sec.BackupLists [fte.BackupList];
78 foreach (BackupEndpointElement bee in bec)
79 list.Add (CreateServiceEndpoint (bee.EndpointName));
84 public RoutingSection ()
86 BackupLists = new BackupListCollection ();
87 Filters = new FilterElementCollection ();
88 FilterTables = new FilterTableCollection ();
89 NamespaceTable = new NamespaceElementCollection ();
92 [ConfigurationProperty ("backupLists", Options = ConfigurationPropertyOptions.None)]
93 public BackupListCollection BackupLists { get; private set; }
95 [ConfigurationProperty ("filters", Options = ConfigurationPropertyOptions.None)]
96 public FilterElementCollection Filters { get; private set; }
98 [ConfigurationProperty ("filterTables", Options = ConfigurationPropertyOptions.None)]
99 public FilterTableCollection FilterTables { get; private set; }
101 [ConfigurationProperty ("namespaceTable", Options = ConfigurationPropertyOptions.None)]
102 public NamespaceElementCollection NamespaceTable { get; private set; }