ProtocolMapping needed config section, default items and support in ServiceHostBase.
authorAtsushi Eno <atsushi@ximian.com>
Fri, 17 Sep 2010 15:23:37 +0000 (00:23 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Fri, 17 Sep 2010 15:23:37 +0000 (00:23 +0900)
data/net_4_0/machine.config
mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ProtocolMappingSection.cs
mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs

index 6d5018518c76ec028e1ce9380e88ed938995cbec..1292eb68e8e49e16e8f124acf543acc707a46c69 100644 (file)
@@ -85,6 +85,7 @@
                        <section name="services" type="System.ServiceModel.Configuration.ServicesSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                        <section name="standardEndpoints" type="System.ServiceModel.Configuration.StandardEndpointsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                        <section name="routing" type="System.ServiceModel.Routing.Configuration.RoutingSection, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
+                       <section name="protocolMapping" type="System.ServiceModel.Configuration.ProtocolMappingSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                </sectionGroup>
                <section name="system.webServer" type="System.Configuration.IgnoreSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                <section name="uri" type="System.Configuration.UriSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
index 9374e13c816b8c7f49f044dc6a679119c0375a57..66a8082dbbd80aae3b74ee7b948d5f7903c68cf8 100644 (file)
@@ -57,17 +57,35 @@ namespace System.ServiceModel.Configuration
 {
        public sealed class ProtocolMappingSection : ConfigurationSection
        {
-               ConfigurationPropertyCollection _properties;
-               
+               static ConfigurationPropertyCollection properties;
+               static ConfigurationProperty collection;
+
+               static ProtocolMappingSection ()
+               {
+                       collection = new ConfigurationProperty ("", typeof (ProtocolMappingElementCollection), null, null, null, ConfigurationPropertyOptions.IsDefaultCollection);
+                       properties = new ConfigurationPropertyCollection ();
+                       properties.Add (collection);
+               }
+
                // Properties
 
                [ConfigurationProperty ("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
                public ProtocolMappingElementCollection ProtocolMappingCollection {
-                       get { return (ProtocolMappingElementCollection) base [""]; }
+                       get { return (ProtocolMappingElementCollection) base [collection]; }
                }
 
                protected override ConfigurationPropertyCollection Properties {
-                       get { return base.Properties; }
+                       get { return properties; }
+               }
+
+               protected override void InitializeDefault ()
+               {
+                       base.InitializeDefault ();
+                       // LAMESPEC: no https?
+                       ProtocolMappingCollection.Add (new ProtocolMappingElement ("http", "basicHttpBinding", null));
+                       ProtocolMappingCollection.Add (new ProtocolMappingElement ("net.tcp", "netTcpBinding", null));
+                       ProtocolMappingCollection.Add (new ProtocolMappingElement ("net.msmq", "netMsmqBinding", null));
+                       ProtocolMappingCollection.Add (new ProtocolMappingElement ("net.pipe", "netNamedPipeBinding", null));
                }
        }
 
index 152f54e60324cd1b0bf6bda327b53c5879fdcbc6..cc12e2a8fd82aa8e81ef0d73c3e71b76783d8727 100644 (file)
@@ -478,6 +478,22 @@ namespace System.ServiceModel
                        foreach (ServiceEndpoint endPoint in Description.Endpoints)
                                endPoint.Validate ();
 
+#if NET_4_0
+                       // In 4.0, it seems that if there is no configured ServiceEndpoint, infer them from the service type.
+                       if (Description.Endpoints.Count == 0) {
+                               foreach (Type iface in Description.ServiceType.GetInterfaces ())
+                                       if (iface.GetCustomAttributes (typeof (ServiceContractAttribute), true).Length > 0)
+                                               foreach (var baddr in BaseAddresses) {
+                                                       if (!baddr.IsAbsoluteUri)
+                                                               continue;
+                                                       var binding = GetBindingByProtocolMapping (baddr);
+                                                       if (binding == null)
+                                                               continue;
+                                                       AddServiceEndpoint (iface.FullName, binding, baddr);
+                                               }
+                       }
+#endif
+
                        if (Description.Endpoints.FirstOrDefault (e => e.Contract != mex_contract && !e.IsSystemEndpoint) == null)
                                throw new InvalidOperationException ("The ServiceHost must have at least one application endpoint (that does not include metadata exchange endpoint) defined by either configuration, behaviors or call to AddServiceEndpoint methods.");
                }