Example #1
0
        protected override void ApplyConfiguration(string configurationName)
        {
            if (m_clientChannelFactoryConfiguration.IsCustomConfig && m_clientChannelFactoryConfiguration.ServiceModelSection != null)
            {
                ChannelEndpointElement selectedEndpoint = null;

                foreach (ChannelEndpointElement endpoint in m_clientChannelFactoryConfiguration.ServiceModelSection.Client.Endpoints)
                {
                    if (StringUtil.CompareIgnoreCase(endpoint.Name, configurationName))
                    {
                        selectedEndpoint = endpoint;
                        break;
                    }
                }

                if (selectedEndpoint != null)
                {
                    if (this.Endpoint.Binding == null)
                    {
                        this.Endpoint.Binding = ServicesUtil.CreateBinding(
                            selectedEndpoint.Binding,
                            selectedEndpoint.BindingConfiguration,
                            m_clientChannelFactoryConfiguration.ServiceModelSection);
                    }

                    if (this.Endpoint.Address == null)
                    {
                        this.Endpoint.Address = new EndpointAddress(
                            selectedEndpoint.Address,
                            GetIdentity(selectedEndpoint.Identity),
                            selectedEndpoint.Headers.Headers);
                    }

                    if (this.Endpoint.Behaviors.Count == 0 && selectedEndpoint.BehaviorConfiguration != null)
                    {
                        ServicesUtil.AddBehaviors(
                            selectedEndpoint.BehaviorConfiguration,
                            this.Endpoint,
                            m_clientChannelFactoryConfiguration.ServiceModelSection);
                    }

                    this.Endpoint.Name = selectedEndpoint.Name;
                }
            }

            EnsureClientInterceptorBehavior(this.Endpoint);

            if (!m_clientChannelFactoryConfiguration.IsCustomConfig)
            {
                base.ApplyConfiguration(configurationName);
            }

            if (m_clientChannelFactoryConfiguration.Credentials != null)
            {
                EnsureClientCredentials(
                    this.Endpoint,
                    m_clientChannelFactoryConfiguration.Credentials.UserName.UserName,
                    m_clientChannelFactoryConfiguration.Credentials.UserName.Password);
            }
        }
Example #2
0
        protected override void ApplyConfiguration()
        {
            if (m_clientChannelFactoryConfiguration.ServiceModelSection.Services.Services.Count > 0)
            {
                ServiceEndpointElement selectedEndpoint = null;

                foreach (ServiceElement serviceElement in m_clientChannelFactoryConfiguration.ServiceModelSection.Services.Services)
                {
                    if (StringUtil.CompareIgnoreCase(serviceElement.Name, this.Description.Name))
                    {
                        selectedEndpoint = serviceElement.Endpoints[0];
                        break;
                    }
                }

                if (selectedEndpoint != null)
                {
                    if (this.Description.Endpoints == null || this.Description.Endpoints.Count == 0)
                    {
                        if (StringUtil.CompareIgnoreCase(selectedEndpoint.Address.Host, MachineInfo.MachineName) == false)
                        {
                            // Ensure no "localhost" as Uri host name.
                            selectedEndpoint.Address = new Uri(selectedEndpoint.Address.ToString().Replace(selectedEndpoint.Address.Host, MachineInfo.MachineName));
                        }

                        var serviceEndpoint = new ServiceEndpoint(
                            ContractDescription.GetContract(typeof(T)),
                            ServicesUtil.GetBinding(selectedEndpoint.Address, selectedEndpoint.BindingConfiguration),
                            new EndpointAddress(selectedEndpoint.Address));

                        if (StringUtil.IsStringInitialized(selectedEndpoint.Name))
                        {
                            serviceEndpoint.Name = selectedEndpoint.Name;
                        }

                        this.Description.Endpoints.Add(serviceEndpoint);
                    }
                }
            }
            else
            {
                base.ApplyConfiguration();
            }
        }