/// <summary> /// Creates a channel factory. /// </summary> /// <typeparam name="TChannel">The type of the channel.</typeparam> /// <param name="endpoint">The endpoint configuration.</param> /// <param name="baseAddresses">The base addresses.</param> /// <returns></returns> public static ChannelFactory <TChannel> CreateChannelFactory <TChannel>(WcfClientEndpoint endpoint, params Uri[] baseAddresses) { if (endpoint == null) { throw new ArgumentNullException("endpoint"); } if (endpoint.BindingXml == null) { throw new ArgumentNullException("endpoint.BindingXml"); } var binding = endpoint.BindingXml.CreateBinding(); var address = endpoint.BindingXml.CreateAddress(endpoint.Address, baseAddresses); var endpointAddress = new EndpointAddress(new Uri(address), endpoint.IdentityXml == null ? null : endpoint.IdentityXml.CreateEndpointIdentity(), endpoint.HeadersXml == null ? null : endpoint.HeadersXml.CreateAddressHeaders()); var factory = new ChannelFactory <TChannel>(binding, endpointAddress); if (endpoint.EndpointBehaviorXml != null) { endpoint.EndpointBehaviorXml.ApplyEndpointBehaviorConfiguration(factory.Endpoint); } return(factory); }
public static WcfClientEndpoint LoadWcfClientEndpointConfiguration(Type serviceContractType) { var endpointElement = _xmlDoc.SelectSingleNode("/WcfConfiguration/Client/endpoint[@contract='" + serviceContractType.ToString() + "']"); var endpointConfig = new WcfClientEndpoint { ServiceContractType = endpointElement.Attributes["contract"].Value, }; if (endpointElement.Attributes["address"] != null) { endpointConfig.Address = endpointElement.Attributes["address"].Value; } var bindingTypeCode = endpointElement.Attributes["binding"].Value; if (endpointElement.Attributes["bindingConfiguration"] == null) { endpointConfig.BindingXml = new BindingXml(bindingTypeCode, null); } else { var bindingConfigName = endpointElement.Attributes["bindingConfiguration"].Value; var bindingElement = _xmlDoc.SelectSingleNode("/WcfConfiguration/Bindings/binding[@name='" + bindingConfigName + "']"); endpointConfig.BindingXml = new BindingXml(bindingTypeCode, bindingElement.OuterXml); } return(endpointConfig); }