贴一个解析app.config内容的代码,抛砖引玉,注意这个ConfigurationManager.cs,要放在项目根路径下
全算上,50行吧using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Resources;
using System.Xml.Linq;namespace EcToEv.Util
{
    /// <summary>
    /// Access appSettings from a configuration file
    /// </summary>
    /// <res>Your appConfig file must be in the root of your applcation</res>
    public static class ConfigurationManager
    {
        static ConfigurationManager()
        {
            AppSettings = new Dictionary<string, string>();
            ReadSettings();
        }        public static Dictionary<string, string> AppSettings { get; set; }
        private static void ReadSettings()
        {
            // Get the name of the executing assemby - we are going to be looking in the root folder for
            // a file called app.config
            string assemblyName = Assembly.GetExecutingAssembly().FullName;
            assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(','));
            string url = String.Format("{0};component/app.config", assemblyName);
            StreamResourceInfo configFile = Application.GetResourceStream(new Uri(url, UriKind.Relative));
            if (configFile != null && configFile.Stream != null)
            {
                Stream stream = configFile.Stream;
                XDocument document = XDocument.Load(stream);
                foreach (XElement element in document.Descendants("appSettings").DescendantNodes())
                {
                    AppSettings.Add(element.Attribute("key").Value, element.Attribute("value").Value);
                }
            }
        }
    }
}

解决方案 »

  1.   

    楼上你是没看我的问题内容么....  你这个代码只是解析下appsettings节的键值对而已. 你要知道wcf的配置有多少....
      

  2.   

    按我的理解, 一个应用程序, 就应该只有一个app.config就好, 不管有多个少exe比如上面的A.exe, B.exe, N.exe, 在一个文件夹里, 那么他们的配置要么用mysettings.settings文件或把要用的配置合并到一个app.config内, 就可以了, 按我的理解这样应该没错吧?
    但是在注册完B.exe到系统services内之后, 总是无法启动, 看事件日志说应用有0个终结点, 这可能是因为没有配置文件造成的, 它没有去读取app.config内的配置, 搞不懂啊.. 抓狂.
      

  3.   

    已解决. 在别的项目中可以添加对主程序的app.config的快捷方式.  再把项目的编译输出改至主项目的目录中即可.