Turned out that they had nothing to do with #668089..
}
#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;
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
}
// behaviors
AddServiceBehaviors (service.BehaviorConfiguration, true);
- // services
+ // endpoints
foreach (ServiceEndpointElement endpoint in service.Endpoints) {
ServiceEndpoint se;
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
}
}
-#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)
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);