<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" />
{
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));
}
}
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.");
}