/// <summary>
        /// Interrogates the app.config file to get a list of WCF client end points that implement the ISIPMonitorPublisher contract.
        /// This is to allow this class to connect to multiple notification servers if needed.
        /// </summary>
        private List <string> GetClientEndPointNames()
        {
            List <string> clientEndPointNames = new List <string>();

            //ServiceModelSectionGroup serviceModelSectionGroup = (ServiceModelSectionGroup)ConfigurationManager.GetSection("system.serviceModel");
            ServiceModelSectionGroup serviceModelSectionGroup = null;

            try
            {
                serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            }
            catch
            {
                serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~"));
            }

            foreach (ChannelEndpointElement client in serviceModelSectionGroup.Client.Endpoints)
            {
                if (client.Contract == CLIENT_CONTRACT && !clientEndPointNames.Contains(client.Name))
                {
                    logger.Debug("MonitorProxyManager found client endpoint for ISIPMonitorPublisher, name=" + client.Name + ".");
                    clientEndPointNames.Add(client.Name);
                }
            }

            return(clientEndPointNames);
        }
Пример #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            WebAPIBuilder.BuildWebAPI(ServiceConfiguration.WebAPIUrl);
            WCFHost wcfHost = new WCFHost();

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                Console.WriteLine("WCFHost running on console mode.");
                Configuration            configuration   = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ServiceModelSectionGroup serviceModel    = ServiceModelSectionGroup.GetSectionGroup(configuration);
                ServicesSection          servicesSection = serviceModel.Services;

                foreach (ServiceEndpointElement endpoint in servicesSection.Services.Cast <ServiceElement>().Select(s => s.Endpoints).SelectMany(ss => ss.OfType <ServiceEndpointElement>()))
                {
                    Console.WriteLine("Address: {0}", endpoint.Address);
                }

                wcfHost.Start();

                Console.WriteLine("Press any key to stop program...");
                Console.ReadKey();

                wcfHost.Stop();
            }
            else
            {
                ServiceBase.Run(wcfHost);
            }
        }
Пример #3
0
        public override List <string> GetBaseAddresses(EndpointConfig config)
        {
            List <string> ret = new List <string>();

            Configuration svcconfig = GetConfiguration(true);

            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(svcconfig);
            ServiceElementCollection serviceColl = sg.Services.Services;


            ServiceElement serviceElement = null;

            // Find serviceElement
            foreach (ServiceElement el in serviceColl)
            {
                if (config.MatchServiceType(el.Name))
                {
                    serviceElement = el;
                    break;
                }
            }

            if (null == serviceElement)
            {
                return(ret);
            }

            foreach (BaseAddressElement element in serviceElement.Host.BaseAddresses)
            {
                ret.Add(element.BaseAddress);
            }

            return(ret);
        }
Пример #4
0
        /// <summary>
        /// Adds the given endpoint unless its already configured in app.config
        /// </summary>
        /// <param name="contractType"></param>
        /// <param name="binding"></param>
        /// <param name="address"></param>
        public void AddDefaultEndpoint(Type contractType, Binding binding, string address)
        {
            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            if (serviceModel == null)
            {
                throw new InvalidOperationException("No service model section found in config");
            }

            bool endpointAlreadyConfigured = false;

            foreach (ServiceElement se in serviceModel.Services.Services)
            {
                if (se.Name == Description.ConfigurationName)
                {
                    foreach (ServiceEndpointElement endpoint in se.Endpoints)
                    {
                        if (endpoint.Contract == contractType.FullName && endpoint.Address.OriginalString == address)
                        {
                            endpointAlreadyConfigured = true;
                        }
                    }
                }
            }
            if (!endpointAlreadyConfigured)
            {
                logger.Debug("Endpoint for contract: " + contractType.Name + " is not found in configuration, going to add it programatically");
                AddServiceEndpoint(contractType, binding, address);
            }
        }
Пример #5
0
        public IHttpActionResult GetBindings([FromUri] string bindingType)
        {
            var            serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            IList <string> result       = serviceModel.Bindings[bindingType].ConfiguredBindings.Select(x => x.Name).ToList();

            return(Ok(result));
        }
        private static string ReadServiceName()
        {
            string _ServiceName = string.Empty;
            var    serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            var    endpoints    = serviceModel.Services.Services;

            foreach (ServiceElement e in endpoints)
            {
                if (e.Name == "WcfServiceLibrary.ObservableService")
                {
                    foreach (ServiceEndpointElement item in e.Endpoints)
                    {
                        if (item.Name == "PeerEndpoint")
                        {
                            _ServiceName = $"{e.Host.BaseAddresses[0].BaseAddress.ToString()}";
                            var test = new Uri(_ServiceName);
                            _ServiceName = $"{test.Host}:{test.Port}";

                            break;
                        }
                    }
                    break;
                }
            }
            return(_ServiceName);
        }
        void Connect()
        {
            var group = ServiceModelSectionGroup.GetSectionGroup(
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            //create duplex channel factory
            var serviceFactory = new DuplexChannelFactory <IBoardService>(
                this, group.Client.Endpoints[0].Name);

            //create a communication channel and register for its events
            this.serviceProxy = serviceFactory.CreateChannel();

            var channel = (IClientChannel)this.serviceProxy;

            channel.Open();
            channel.Closed  += this.OnChannelClosed;
            channel.Faulted += this.OnChannelClosed;


            this.board.Creatures.Clear();
            foreach (var creature in this.serviceProxy.GetCreatures())
            {
                this.board.Creatures.Add(creature);
            }
        }
Пример #8
0
        private void StartHost()
        {
            var group =
                ServiceModelSectionGroup.GetSectionGroup(
                    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            if (group != null)
            {
                //take the first service and endpoint definition
                var service     = group.Services.Services[0];
                var baseAddress =
                    service.Endpoints[0].Address.AbsoluteUri.Replace(service.Endpoints[0].Address.AbsolutePath,
                                                                     String.Empty);
                //create service
                var productService = new ProductService(this);
                //create host
                var host = new ServiceHost(productService, new[] { new Uri(baseAddress) });
                host.AddServiceEndpoint(typeof(IProductService),
                                        new NetNamedPipeBinding(), service.Endpoints[0].Address.AbsolutePath);

                try
                {
                    //open host
                    host.Open();
                }
                catch (CommunicationObjectFaultedException cofe)
                {
                    //log exception
                }
                catch (TimeoutException te)
                {
                    //log exception
                }
            }
        }
Пример #9
0
        public static void EnumerateAvailableServiceEndpoints(string serviceConfigFile)
        {
            var fileMap = new ExeConfigurationFileMap {
                ExeConfigFilename = serviceConfigFile
            };
            var appConfig    = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);


            if (serviceModel == null)
            {
                return;
            }

            Trace.WriteLine("Service Name: Configuration Name : Address : Binding : Contract");
            foreach (ServiceElement service in serviceModel.Services.Services)
            {
                foreach (ServiceEndpointElement endpoint in service.Endpoints)
                {
                    Trace.WriteLine(String.Format("{0} : {1} : {2} : {3} : {4}",
                                                  service.Name,
                                                  endpoint.Name,
                                                  endpoint.Address,
                                                  endpoint.Binding,
                                                  endpoint.Contract));
                }
            }
        }
Пример #10
0
        /// <summary>
        /// LookupEndpoint
        /// </summary>
        /// <param name="endpointName"></param>
        /// <returns></returns>
        private string LookupEndpoint(string endpointName)
        {
            if (string.IsNullOrWhiteSpace(endpointName))
            {
                return("*");
            }

            Configuration          config          = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ClientSection          clientSection   = ServiceModelSectionGroup.GetSectionGroup(config).Client;
            ChannelEndpointElement endpointElement = null;

            foreach (ChannelEndpointElement element in clientSection.Endpoints)
            {
                if (element.Name.EndsWith("_" + endpointName, StringComparison.OrdinalIgnoreCase) &&
                    element.Contract == typeof(TChannel).FullName)
                {
                    endpointElement = element;
                    break;
                }
            }
            if (endpointElement == null)
            {
                return("*");
            }
            return(endpointElement.Name);
        }
Пример #11
0
        public static void EnumerateAvailableClientEndpoints()
        {
            Configuration            appConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);

            if (serviceModel == null)
            {
                return;
            }

            if (100 > Console.WindowWidth)
            {
                Console.WindowWidth = 100;
            }

            Console.WriteLine("Configuration Name : Address : Binding : Contract");

            foreach (ChannelEndpointElement endpoint in serviceModel.Client.Endpoints)
            {
                Console.WriteLine("{0} : {1} : {2} : {3}",
                                  endpoint.Name,
                                  endpoint.Address,
                                  endpoint.Binding,
                                  endpoint.Contract);
            }
        }
Пример #12
0
        private ChannelEndpointElementCollection ReadClientServices()
        {
            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(_configFile);
            var endpoints    = serviceModel.Client.Endpoints;

            return(endpoints);
        }
Пример #13
0
        private void Connect()
        {
            //get endpoint configuration from app.config.
            var group =
                ServiceModelSectionGroup.GetSectionGroup(
                    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            if (group != null)
            {
                //create duplex channel factory
                pipeFactory = new DuplexChannelFactory <IProductService>(this, group.Client.Endpoints[0].Name);

                //create a communication channel and register for its events
                pipeProxy = pipeFactory.CreateChannel();
                ((IClientChannel)pipeProxy).Faulted += PipeProxyFaulted;
                ((IClientChannel)pipeProxy).Opened  += PipeProxyOpened;

                try
                {
                    //try to open the connection
                    ((IClientChannel)pipeProxy).Open();
                    this.checkConnectionTimer.Stop();

                    //register for added products
                    pipeProxy.RegisterForAddedProducts();
                }
                catch
                {
                    //for example show status text or log;
                }
            }
        }
Пример #14
0
        static ServiceModelSectionGroup GetSection()
        {
            var appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var config    = ServiceModelSectionGroup.GetSectionGroup(appConfig);

            return(config);
        }
Пример #15
0
        private bool UseConfig()
        {
            try
            {
                string        uri  = Assembly.GetExecutingAssembly().CodeBase;
                string        file = new Uri(uri).LocalPath;
                string        bin  = Path.GetDirectoryName(file);
                DirectoryInfo root = new DirectoryInfo(bin).Parent;

                Configuration            config     = WebConfigurationManager.OpenWebConfiguration("/");
                ServiceModelSectionGroup sectionGrp = ServiceModelSectionGroup.GetSectionGroup(config);

                ChannelEndpointElementCollection endpoints = sectionGrp.Client.Endpoints;
                foreach (ChannelEndpointElement endpoint in endpoints)
                {
                    if (endpoint.Name == AppConfig.EndpointConfig)
                    {
                        Log.Write(TraceEventType.Information, "CompareService: service.model section found");
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(TraceEventType.Error, "{0}", ex);
            }
            Log.Write(TraceEventType.Information, "CompareService: service.model section not found");
            return(false);
        }
Пример #16
0
        public static System.ServiceModel.Description.ServiceEndpoint GetServiceEndpoint <T>() where T : IClientChannel
        {
            var configFullName = Assembly.GetExecutingAssembly().Location + ".config";
            var configuration  = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap {
                ExeConfigFilename = configFullName
            }, ConfigurationUserLevel.None);

            var channelType       = typeof(T);
            var contractType      = channelType.GetInterfaces().First(i => i.Namespace == channelType.Namespace);
            var contractAttribute = contractType.GetCustomAttributes(typeof(ServiceContractAttribute), false).First() as ServiceContractAttribute;

            var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
            var channelEndpointElement   = serviceModelSectionGroup?.Client.Endpoints.OfType <ChannelEndpointElement>().First(e => e.Contract == contractAttribute?.ConfigurationName);
            var channelFactory           = new ConfigurationChannelFactory <T>(channelEndpointElement.Name, configuration, null);

            //var binding = channelFactory.Endpoint.Binding as BasicHttpBinding;
            //binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            //binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

            //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            //binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            //binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;

            //channelFactory.Credentials.UserName.UserName = "******";
            //channelFactory.Credentials.UserName.Password = "";

            return(channelFactory.Endpoint);
        }
Пример #17
0
        public List <string> GetServiceNamesFromConfigFile()
        {
            List <string>            ServiceNames = null;
            Configuration            appConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
            ServicesSection          services     = serviceModel.Services;
            ServiceElementCollection sec          = services.Services;

            if (sec.Count > 0)
            {
                ServiceNames   = new List <string>();
                m_serviceTypes = new Dictionary <string, Type>();
                foreach (ServiceElement se in sec)
                {
                    ServiceNames.Add(se.Name);

                    Type t = Type.GetType(se.Name);
                    if (t == null)
                    {
                        string[] sa = se.Name.Split('.');
                        System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(sa[0] + ".dll");
                        t = a.GetType(se.Name);
                    }

                    m_serviceTypes.Add(se.Name, t);
                }
            }
            return(ServiceNames);
        }
Пример #18
0
        private static StandardBindingElement GetBindingElement(string bindingName, string sBindingType, out Type oBindingType)
        {
            oBindingType = null;
            StandardBindingElement bindingElement = null;

            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(_config);

            foreach (var bindingCollection in serviceModel.Bindings.BindingCollections)
            {
                if (bindingCollection.BindingName == sBindingType)
                {
                    foreach (var bindingElem in bindingCollection.ConfiguredBindings)
                    {
                        if (bindingElem.Name == bindingName)
                        {
                            bindingElement = (StandardBindingElement)bindingElem;
                            oBindingType   = bindingCollection.BindingType;
                            break;
                        }
                    }
                }
                if (bindingElement != null)
                {
                    break;
                }
            }
            return(bindingElement);
        }
Пример #19
0
        /// <summary>
        /// The get services.
        /// </summary>
        /// <returns>
        /// The <see cref="System.ServiceModel.Configuration.ServiceElementCollection"/>.
        /// </returns>
        public static ServiceElementCollection GetServices()
        {
            string        baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            Configuration config;

            try
            {
                config = WebConfigurationManager.OpenWebConfiguration(baseDirectory);
            }
            catch (Exception ex1)
            {
                try
                {
                    config = WebConfigurationManager.OpenWebConfiguration("~");
                }
                catch (Exception ex2)
                {
                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, "Unable to load web.config for WCF services inspection. If you run WebORB using ASP.NET Development Server, make sure to start Visual Studio 'as Administrator'");
                        Log.log(LoggingConstants.ERROR, ex1);
                        Log.log(LoggingConstants.ERROR, ex2);
                    }

                    return(null);
                }
            }

            Log.log(LoggingConstants.INFO, "CONFIG PATH - " + config.FilePath);
            return(ServiceModelSectionGroup.GetSectionGroup(config).With(x => x.Services).Services);
        }
Пример #20
0
        public IHttpActionResult GetBindingTypes()
        {
            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            var types        = serviceModel.Bindings.BindingCollections.Select(x => x.BindingName);

            return(Ok(types));
        }
Пример #21
0
        protected override void ApplyConfiguration()
        {
            ExeConfigurationFileMap filemap = new ExeConfigurationFileMap();

            filemap.ExeConfigFilename = _configurationPath;

            Configuration            config       = ConfigurationManager.OpenMappedExeConfiguration(filemap, ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);

            bool loaded = false;

            foreach (ServiceElement se in serviceModel.Services.Services)
            {
                if (!loaded &&
                    se.Name == this.Description.ConfigurationName)
                {
                    base.LoadConfigurationSection(se);
                    loaded = true;
                }
            }

            if (!loaded)
            {
                throw new ArgumentException(string.Format("ServiceElement doesn't exist in the configuration file: {0}", _configurationPath));
            }
        }
Пример #22
0
        private static ChannelEndpointElement GetEndPointElement(string configurationName)
        {
            var config       = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config);

            if (sectionGroup == null)
            {
                throw new ConfigurationErrorsException(Resources.GroupExpectedErrorMessage);
            }

            var client       = sectionGroup.Client;
            var contractType = typeof(TService);
            var endPoint     = client.Endpoints.OfType <ChannelEndpointElement>()
                               .FirstOrDefault(ep =>
                                               (ep.Name == configurationName) ||
                                               (ep.Contract == contractType.Name) ||
                                               (ep.Contract == contractType.AssemblyQualifiedName) ||
                                               (ep.Contract == contractType.FullName));

            if (endPoint != null)
            {
                return(endPoint);
            }

            var errorMessage = string.Format(Resources.EndPointMissingErrorMessage,
                                             contractType.AssemblyQualifiedName);

            throw new ConfigurationErrorsException(errorMessage);
        }
Пример #23
0
            static EndpointAddress GetAddressFromClientConfig(Type type, string endpointName = null)
            {
                Debug.Assert(type.IsInterface);

                Configuration            config       = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config);

                EndpointAddress address = null;

                foreach (ChannelEndpointElement endpointElement in sectionGroup.Client.Endpoints)
                {
                    if ((String.IsNullOrEmpty(endpointName)) && (endpointElement.Contract == type.ToString()))
                    {
                        address = new EndpointAddress(endpointElement.Address);
                        break;
                    }
                    else
                    {
                        if (endpointElement.Name == endpointName)
                        {
                            address = new EndpointAddress(endpointElement.Address);
                            break;
                        }
                    }
                }
                return(address);
            }
Пример #24
0
        protected void EnsureComMetaDataExchangeBehaviorAdded(Configuration config)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);

            if (!sg.Behaviors.ServiceBehaviors.ContainsKey(comServiceBehavior))
            {
                ServiceBehaviorElement behavior = new ServiceBehaviorElement(comServiceBehavior);
                sg.Behaviors.ServiceBehaviors.Add(behavior);
                ServiceMetadataPublishingElement metadataPublishing = new ServiceMetadataPublishingElement();

                if (Tool.Options.Hosting == Hosting.Complus || Tool.Options.Hosting == Hosting.NotSpecified)
                {
                    metadataPublishing.HttpGetEnabled = false;
                }
                else
                {
                    metadataPublishing.HttpGetEnabled = true;
                }
                behavior.Add(metadataPublishing);

                ServiceDebugElement serviceDebug = new ServiceDebugElement();
                serviceDebug.IncludeExceptionDetailInFaults = false;
                behavior.Add(serviceDebug);
            }
        }
Пример #25
0
        public List <string> GetClientNamesFromConfigFile()
        {
            List <string>            ClientNames = null;
            string                   name;
            Configuration            appConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
            ClientSection            clients      = serviceModel.Client;

            ChannelEndpointElementCollection cepec = clients.Endpoints;

            if (cepec.Count > 0)
            {
                ClientNames       = new List <string>();
                m_ClientEndPoints = new List <EndPoint>();

                foreach (ChannelEndpointElement cepe in cepec)
                {
                    string[] sa = cepe.Contract.ToString().Split('.');
                    name = sa[0] + "(" + cepe.Binding + ")";


                    m_ClientEndPoints.Add(new EndPoint(cepe.Name, sa[0]));
                    ClientNames.Add(name);
                }
            }

            return(ClientNames);
        }
Пример #26
0
        private static void HostServices()
        {
            EnsureQueueExists();

            List <ServiceHost> lHosts = new List <ServiceHost>();

            try
            {
                Configuration            lAppConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ServiceModelSectionGroup lServiceModel = ServiceModelSectionGroup.GetSectionGroup(lAppConfig);

                System.ServiceModel.Configuration.ServicesSection lServices = lServiceModel.Services;
                foreach (ServiceElement lServiceElement in lServices.Services)
                {
                    ServiceHost lHost = new ServiceHost(Type.GetType(GetAssemblyQualifiedServiceName(lServiceElement.Name)));
                    lHost.Open();
                    lHosts.Add(lHost);
                }
                Console.WriteLine("VideoStore Service Started, press Q key to quit");
                while (Console.ReadKey().Key != ConsoleKey.Q)
                {
                    ;
                }
            }
            finally
            {
                foreach (ServiceHost lHost in lHosts)
                {
                    lHost.Close();
                }
            }
        }
Пример #27
0
        private void LoadFromFile(string configFilePath)
        {
            var filemap = new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configFilePath
            };
            var config       = ConfigurationManager.OpenMappedExeConfiguration(filemap, ConfigurationUserLevel.None);
            var serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);

            bool loaded = false;

            foreach (ServiceElement se in serviceModel.Services.Services)
            {
                if (!loaded)
                {
                    if (se.Name == this.Description.ConfigurationName)
                    {
                        base.LoadConfigurationSection(se);
                        loaded = true;
                    }
                }
            }
            if (!loaded)
            {
                throw new ArgumentException("ServiceElement doesn't exist");
            }
        }
Пример #28
0
        /// <summary>
        /// Retourne l'uri associé au point d'accès principal de l'application.
        ///
        /// Pour les applications, l'uri est de la forme :
        ///   - MACHINE_NAME;http[s]://logical_name:port/[path]/.
        /// </summary>
        /// <returns>Uri du point d'accès principal de l'application.</returns>
        private static string GetEndPointUri()
        {
            if (HttpContext.Current != null)
            {
                return(Environment.MachineName);
            }
            else
            {
                try {
                    System.Configuration.Configuration configuration       = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    ServiceModelSectionGroup           serviceModelSection = ServiceModelSectionGroup.GetSectionGroup(configuration);
                    if (serviceModelSection != null)
                    {
                        foreach (ServiceElement service in serviceModelSection.Services.Services)
                        {
                            foreach (ServiceEndpointElement sep in service.Endpoints)
                            {
                                if (sep.Address != null)
                                {
                                    return(sep.Address.ToString());
                                }
                            }
                        }
                    }
                } catch (ArgumentException) {
                    return(Environment.MachineName);
                }

                return(Environment.MachineName);
            }
        }
        int NumEndpointsForClsid(Configuration config, Guid clsid, Guid appId)
        {
            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;

            foreach (ServiceElement se in serviceColl)
            {
                string[] serviceParams = se.Name.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }

                Guid serviceAppId;
                Guid serviceClsid;

                try
                {
                    serviceAppId = new Guid(serviceParams[0]);
                    serviceClsid = new Guid(serviceParams[1]);
                }
                catch (FormatException)
                {
                    // Only Guid serviceTypes are of interest to us - those are the ones our listener picks up
                    continue;
                }

                if (serviceClsid == clsid && serviceAppId == appId)
                {
                    return(se.Endpoints.Count);
                }
            }

            return(0);
        }
        protected ServiceModelSectionGroup GetServiceModelSectionGroup()
        {
            var group =
                ServiceModelSectionGroup.GetSectionGroup(
                    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            return(@group);
        }