怎样使用web.config

来源:互联网 发布:java web 视频播放 编辑:程序博客网 时间:2024/05/17 23:06
通过帮助文件问题解决了,代码共分享:
// 服务端svc
  [OperationContract]
         public string get_web_config_appSettings_value(string path,string key) 
         {
        
             string _value = "";
             System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(path);
             if (0 < rootWebConfig1.AppSettings.Settings.Count)
             {
                 System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings[key];
                 if (null != customSetting) _value = customSetting.Value;
             }
             return _value;

         }

// silverlight端
   _subject = new madamingSubject(@"../Services/Service1.svc");
             _subject.WCF.get_web_config_appSettings_valueCompleted += new EventHandler<ServiceReference1.get_web_config_appSettings_valueCompletedEventArgs>(WCF_get_web_config_appSettings_valueCompleted);


   private void hyperlinkbutton_调试_Click(object sender, RoutedEventArgs e)
         {
             Uri _uri = new Uri(Application.Current.Host.Source, @"../");

             //string path = string.Format("AbsolutePath: {0}\nAbsoluteUri: {1}\nDnsSafeHost: {2}\nHost: {3}\nLocalPath: {4}\nToString: {5}", _uri.AbsolutePath, _uri.AbsoluteUri, _uri.DnsSafeHost, _uri.Host, _uri.LocalPath, _uri.ToString());
             //MessageBox.Show(path);

             _subject.WCF.get_web_config_appSettings_valueAsync(new Uri(Application.Current.Host.Source, @"../").LocalPath, "MapTileImagesURL");

         }
      private void WCF_get_web_config_appSettings_valueCompleted(object sender, ServiceReference1.get_web_config_appSettings_valueCompletedEventArgs e) 
         {
             _subject.地图源 = e.Result;
             textblock_副标题.Text = string.Format("[地图源:{0}]", _subject.地图源);
             

//            MessageBox.Show(e.Result );
         }