standard endpoint and protocol mapping support were lacking at client side.
authorAtsushi Eno <atsushi@ximian.com>
Tue, 1 Feb 2011 11:25:40 +0000 (20:25 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Tue, 1 Feb 2011 11:25:40 +0000 (20:25 +0900)
Turned out that they had nothing to do with #668089..

mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs
mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory.cs
mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs

index bb24e605e05ae6ce84be245cd137d0c6be0a2fb9..aec08d49c876bac9913899defa0d20b0bf9ab206 100644 (file)
@@ -99,6 +99,49 @@ namespace System.ServiceModel.Configuration
                }
 
 #if NET_4_0
+               public static Binding GetBindingByProtocolMapping (Uri address)
+               {
+                       ProtocolMappingElement el = ConfigUtil.ProtocolMappingSection.ProtocolMappingCollection [address.Scheme];
+                       if (el == null)
+                               return null;
+                       return ConfigUtil.CreateBinding (el.Binding, el.BindingConfiguration);
+               }
+
+               public static ServiceEndpoint ConfigureStandardEndpoint (ContractDescription cd, ChannelEndpointElement element)
+               {
+                       string kind = element.Kind;
+                       string endpointConfiguration = element.EndpointConfiguration;
+
+                       EndpointCollectionElement section = ConfigUtil.StandardEndpointsSection [kind];
+                       if (section == null)
+                               throw new ArgumentException (String.Format ("standard endpoint section for '{0}' was not found.", kind));
+
+                       StandardEndpointElement e = section.GetDefaultStandardEndpointElement ();
+
+                       ServiceEndpoint inst = e.CreateServiceEndpoint (cd);
+
+                       foreach (StandardEndpointElement el in section.ConfiguredEndpoints) {
+                               if (el.Name == endpointConfiguration) {
+                                       el.InitializeAndValidate (element);
+                                       el.ApplyConfiguration (inst, element);
+                                       break;
+                               }
+                       }
+                       
+                       return inst;
+               }
+
+               public static Type GetTypeFromConfigString (string name)
+               {
+                       Type type = Type.GetType (name);
+                       if (type != null)
+                               return type;
+                       foreach (var ass in AppDomain.CurrentDomain.GetAssemblies ())
+                               if ((type = ass.GetType (name)) != null)
+                                       return type;
+                       return null;
+               }
+
                public static ServiceEndpoint ConfigureStandardEndpoint (ContractDescription cd, ServiceEndpointElement element)
                {
                        string kind = element.Kind;
index 1b8f2338dea9376325b9210cbedf59e219fcc85d..80c04e08be7ba447bf2cd541d714d57fd8222d86 100644 (file)
@@ -117,25 +117,45 @@ namespace System.ServiceModel
 
                        string contractName = Endpoint.Contract.ConfigurationName;
                        ClientSection client = ConfigUtil.ClientSection;
-                       ChannelEndpointElement res = null;
+                       ChannelEndpointElement endpoint = null;
+
                        foreach (ChannelEndpointElement el in client.Endpoints) {
                                if (el.Contract == contractName && (endpointConfig == el.Name || endpointConfig == "*")) {
-                                       if (res != null)
+                                       if (endpoint != null)
                                                throw new InvalidOperationException (String.Format ("More then one endpoint matching contract {0} was found.", contractName));
-                                       res = el;
+                                       endpoint = el;
                                }
                        }
 
-                       if (res == null)
+                       if (endpoint == null)
                                throw new InvalidOperationException (String.Format ("Client endpoint configuration '{0}' was not found in {1} endpoints.", endpointConfig, client.Endpoints.Count));
 
+#if NET_4_0
+                       var binding = String.IsNullOrEmpty (endpoint.Binding) ? null : ConfigUtil.CreateBinding (endpoint.Binding, endpoint.BindingConfiguration);
+                       var contract = String.IsNullOrEmpty (endpoint.Contract) ? Endpoint.Contract : ContractDescription.GetContract (ConfigUtil.GetTypeFromConfigString (endpoint.Contract));
+
+                       if (!String.IsNullOrEmpty (endpoint.Kind)) {
+                               var se = ConfigUtil.ConfigureStandardEndpoint (contract, endpoint);
+                               if (se.Binding == null)
+                                       se.Binding = binding;
+                               if (se.Address == null && se.Binding != null) // standard endpoint might have empty address
+                                       se.Address = new EndpointAddress (endpoint.Address);
+                               if (se.Binding == null && se.Address != null) // look for protocol mapping
+                                       se.Binding = ConfigUtil.GetBindingByProtocolMapping (se.Address.Uri);
+
+                               service_endpoint = se;
+                       } else {
+                               if (binding == null && endpoint.Address != null) // look for protocol mapping
+                                       Endpoint.Binding = ConfigUtil.GetBindingByProtocolMapping (endpoint.Address);
+                       }
+#endif
                        if (Endpoint.Binding == null)
-                               Endpoint.Binding = ConfigUtil.CreateBinding (res.Binding, res.BindingConfiguration);
+                               Endpoint.Binding = ConfigUtil.CreateBinding (endpoint.Binding, endpoint.BindingConfiguration);
                        if (Endpoint.Address == null)
-                               Endpoint.Address = new EndpointAddress (res.Address);
+                               Endpoint.Address = new EndpointAddress (endpoint.Address);
 
-                       if (res.BehaviorConfiguration != "")
-                               ApplyBehavior (res.BehaviorConfiguration);
+                       if (endpoint.BehaviorConfiguration != "")
+                               ApplyBehavior (endpoint.BehaviorConfiguration);
 #endif
                }
 
index 2c67788f078a79015eed7f6b999161f77ad439d6..587037715853fcc772cbd262a99c6d7dfc340804 100644 (file)
@@ -380,7 +380,7 @@ namespace System.ServiceModel
                        // behaviors
                        AddServiceBehaviors (service.BehaviorConfiguration, true);
 
-                       // services
+                       // endpoints
                        foreach (ServiceEndpointElement endpoint in service.Endpoints) {
                                ServiceEndpoint se;
 
@@ -395,13 +395,13 @@ namespace System.ServiceModel
                                        if (se.Address == null && se.Binding != null) // standard endpoint might have empty address
                                                se.Address = new EndpointAddress (CreateUri (se.Binding.Scheme, endpoint.Address));
                                        if (se.Binding == null && se.Address != null) // look for protocol mapping
-                                               se.Binding = GetBindingByProtocolMapping (se.Address.Uri);
+                                               se.Binding = ConfigUtil.GetBindingByProtocolMapping (se.Address.Uri);
 
                                        AddServiceEndpoint (se);
                                }
                                else {
                                        if (binding == null && endpoint.Address != null) // look for protocol mapping
-                                               binding = GetBindingByProtocolMapping (endpoint.Address);
+                                               binding = ConfigUtil.GetBindingByProtocolMapping (endpoint.Address);
                                        se = AddServiceEndpoint (endpoint.Contract, binding, endpoint.Address);
                                }
 #else
@@ -419,16 +419,6 @@ namespace System.ServiceModel
                        }
                }
 
-#if NET_4_0
-               Binding GetBindingByProtocolMapping (Uri address)
-               {
-                       ProtocolMappingElement el = ConfigUtil.ProtocolMappingSection.ProtocolMappingCollection [address.Scheme];
-                       if (el == null)
-                               return null;
-                       return ConfigUtil.CreateBinding (el.Binding, el.BindingConfiguration);
-               }
-#endif
-
                private ServiceElement GetServiceElement() {
                        Type serviceType = Description.ServiceType;
                        if (serviceType == null)
@@ -506,7 +496,7 @@ namespace System.ServiceModel
                                                foreach (var baddr in BaseAddresses) {
                                                        if (!baddr.IsAbsoluteUri)
                                                                continue;
-                                                       var binding = GetBindingByProtocolMapping (baddr);
+                                                       var binding = ConfigUtil.GetBindingByProtocolMapping (baddr);
                                                        if (binding == null)
                                                                continue;
                                                        AddServiceEndpoint (iface.FullName, binding, baddr);