예제 #1
0
        /// <summary>
        /// Creates a new EndpointCatalog using the section name in the configuration.
        /// </summary>
        /// <returns>
        ///		EndpointCatalog created from the section in the configuration,
        ///		implementing the IEndpointCatalog interface.
        ///	</returns>
        public IEndpointCatalog CreateCatalog()
        {
            EndpointCatalog catalog = null;

            if (endpointSection != null)
            {
                catalog = new EndpointCatalog();

                foreach (EndpointItemElement endpointItem in endpointSection.EndpointItemCollection)
                {
                    Endpoint endpoint = new Endpoint(endpointItem.Name);
                    catalog.SetEndpoint(endpoint);

                    //if an Address exists for the endpoint, must be the default one.
                    if (endpointItem.Address != null)
                    {
                        endpoint.Default = new EndpointConfig(endpointItem.Address);
                        if (endpointItem.UserName != null)
                        {
                            endpoint.Default.Credential.UserName = endpointItem.UserName;
                        }
                        if (endpointItem.Password != null)
                        {
                            endpoint.Default.Credential.Password = endpointItem.Password;
                        }
                        if (endpointItem.Domain != null)
                        {
                            endpoint.Default.Credential.Domain = endpointItem.Domain;
                        }
                    }

                    foreach (NetworkElement network in endpointItem.Networks)
                    {
                        EndpointConfig config = new EndpointConfig(network.Address);
                        endpoint.SetConfiguration(network.Name, config);

                        if (network.UserName != null)
                        {
                            config.Credential.UserName = network.UserName;
                        }
                        if (network.Password != null)
                        {
                            config.Credential.Password = network.Password;
                        }
                        if (network.Domain != null)
                        {
                            config.Credential.Domain = network.Domain;
                        }
                    }
                }
            }

            return(catalog);
        }
        /// <summary>
        /// Sets the endpoint configuration (address and credential) for a network.
        /// </summary>
        /// <param name="networkName">String with the network name.</param>
        /// <param name="endpointConfiguration">EndpointConfig with the address and credential for the network.</param>
        public void SetConfiguration(string networkName, EndpointConfig endpointConfiguration)
        {
            Guard.ArgumentNotNull(endpointConfiguration, "endpointConfiguration");

            if (String.IsNullOrEmpty(networkName))
            {
                throw new ArgumentException("networkName");
            }

            if (String.IsNullOrEmpty(endpointConfiguration.Address))
            {
                throw new ArgumentException("endpointConfiguration.Address");
            }

            if (configurationCatalog.ContainsKey(networkName))
            {
                configurationCatalog.Remove(networkName);
            }

            configurationCatalog.Add(networkName, endpointConfiguration);
        }