Esempio n. 1
0
        public ConfigurationManagerServiceModelOptions(IServiceProvider builder, string path)
        {
            _holder = builder.GetRequiredService <IConfigurationHolder>();

            _section = new Lazy <ServiceModelSectionGroup>(() =>
            {
                var assembly = Assembly.GetEntryAssembly();
                var basePath = string.IsNullOrEmpty(assembly?.Location) ? AppContext.BaseDirectory : Path.GetDirectoryName(assembly.Location);

                // hack - in .net core 2.1 on linux directory not correct(on unit tests),
                // for example:
                // /home/vsts/.nuget/packages/microsoft.testplatform.testhost/16.7.1/lib/netcoreapp2.1/
                var isNetCore21 = RuntimeInformation.FrameworkDescription.Contains(".NET Core 4.6");
                if (isNetCore21 && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    basePath = AppContext.BaseDirectory;
                }

                var configMap = new ExeConfigurationFileMap(Path.Combine(basePath, "CoreWCF.machine.config"))
                {
                    ExeConfigFilename = path
                };
                System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
                var section = ServiceModelSectionGroup.GetSectionGroup(configuration);

                if (section is null)
                {
                    throw new ServiceModelConfigurationException("Section not found");
                }

                return(section);
            }, true);
        }
Esempio n. 2
0
        private void ReadConfigSection(ServiceModelSectionGroup group)
        {
            if (group is null)
            {
                return;
            }

            AddBinding(group.Bindings?.BasicHttpBinding.Bindings);
            AddBinding(group.Bindings?.NetTcpBinding.Bindings);
            AddBinding(group.Bindings?.NetHttpBinding.Bindings);
            AddBinding(group.Bindings?.WSHttpBinding.Bindings);
            AddEndpoint(group.Services?.Services);
        }