Retrieving WCF Configuration from C#

WcfConfigDetails details = new WcfConfigDetails();
            details.Populated = false;

            Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
            BindingsSection bindings = serviceModel.Bindings;

            ChannelEndpointElement element = (from ChannelEndpointElement p in serviceModel.Client.Endpoints
                                              where p.Name == endPointName
                                              select p).FirstOrDefault();

            if (element == null) { return details; }

            details.Port = element.Address.Port;
            details.HostName = element.Address.Host.ToString();
            details.Populated = true;

            return details;

Comments

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

The ridiculous interview experience