Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel");
- var serviceModelSection = ConfigurationManager.GetSection("appSettings");
- // Automagically find all client endpoints defined in app.config
- ClientSection clientSection =
- ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
- ChannelEndpointElementCollection endpointCollection =
- clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
- List<string> endpointNames = new List<string>();
- foreach (ChannelEndpointElement endpointElement in endpointCollection)
- {
- endpointNames.Add(endpointElement.Name);
- }
- // use endpointNames somehow ...
- public static string GetServerName()
- {
- string serverName = "Unknown";
- Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
- BindingsSection bindings = serviceModel.Bindings;
- ChannelEndpointElementCollection endpoints = serviceModel.Client.Endpoints;
- for(int i=0; i<endpoints.Count; i++)
- {
- ChannelEndpointElement endpointElement = endpoints[i];
- if (endpointElement.Contract == "MyContractName")
- {
- serverName = endpointElement.Address.Host;
- }
- }
- return serverName;
- }
- Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- ServiceModelSectionGroup group = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup(config);
Add Comment
Please, Sign In to add comment