Loading System.ServiceModel configuration section using ConfigurationManager

前端 未结 5 1600
借酒劲吻你
借酒劲吻你 2020-12-07 18:30

Using C# .NET 3.5 and WCF, I\'m trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to).

The o

5条回答
  •  无人及你
    2020-12-07 19:17

    This is what I was looking for thanks to @marxidad for the pointer.

        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

提交回复
热议问题