日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WCF修改App.config配置文件技巧分享

WCF對(duì)App.config配置文件的修改方法我們將會(huì)通過(guò)以下這段代碼為大家詳細(xì)介紹相關(guān)操作方法。希望對(duì)于又需要的朋友們能夠從今天介紹的內(nèi)容中獲得一些幫助,來(lái)解決他們?cè)趯?shí)際應(yīng)用中碰到的一些問(wèn)題。

WCF修改App.config配置文件代碼示例:

 
 
 
  1. using System.ServiceModel.Configuration;using System.Text.
    RegularExpressions;// 修改配置文件
  2. private void ChanageConfig()
  3. {
  4. Configuration config = ConfigurationManager.OpenExeConfiguration
    (Application.ExecutablePath);
  5. ConfigurationSectionGroup sct = config.SectionGroups
    ["system.serviceModel"];
  6. ServiceModelSectionGroup serviceModelSectionGroup = 
    sct as ServiceModelSectionGroup;
  7. ClientSection clientSection = serviceModelSectionGroup.Client;
  8. foreach (ChannelEndpointElement item in clientSection.Endpoints)
  9. {
  10. string pattern = "://.*/";
  11. string address = item.Address.ToString();
  12. string replacement = string.Format("://{0}:{1}/", 
    Global.ServerIP, Global.ServerPort);
  13. address = Regex.Replace(address, pattern, replacement);
  14. item.Address = new Uri(address);
  15. }
  16. config.Save(ConfigurationSaveMode.Modified);
  17. ConfigurationManager.RefreshSection("system.serviceModel");
  18. return;
  19. /*
  20. Configuration configuration = ConfigurationManager.
    OpenExeConfiguration(ConfigurationUserLevel.None);
  21. ServiceModelSectionGroup serviceModelSectionGroup = 
    ServiceModelSectionGroup.GetSectionGroup(configuration);
  22. ClientSection clientSection = serviceModelSectionGroup.Client;
  23. foreach(ChannelEndpointElement item in clientSection.Endpoints)
  24. {
  25. MessageBox.Show(item.Address.Host);
  26. }
  27. configuration.Save();
  28. */
  29. return;
  30. XmlDocument xmlDoc = new XmlDocument();
  31. xmlDoc.Load("Rca.exe.config");
  32. XmlNodeList nodeList = xmlDoc.SelectSingleNode
    ("configuration/appSettings").ChildNodes;
  33. foreach (XmlNode node in nodeList)
  34. {
  35. switch (node.Attributes["key"].InnerText.ToLower())
  36. {
  37. case "serverip":
  38. node.Attributes["value"].InnerText = Global.ServerIP;
  39. break;
  40. case "serverport":
  41. node.Attributes["value"].InnerText = Global.ServerPort;
  42. break;
  43. case "langdataid":
  44. node.Attributes["value"].InnerText = Global.LangDataID;
  45. break;
  46. case "uidataid":
  47. node.Attributes["value"].InnerText = Global.UIDataID;
  48. break;
  49. }
  50. }
  51. nodeList = xmlDoc.SelectSingleNode("configuration/
    system.serviceModel/client").ChildNodes;
  52. foreach (XmlNode node in nodeList)
  53. {
  54. string pattern = "://.*/";
  55. string address = node.Attributes["address"].InnerText;
  56. string replacement = string.Format("://{0}:{1}/", 
    Global.ServerIP, Global.ServerPort);
  57. address = Regex.Replace(address, pattern, replacement);
  58. node.Attributes["address"].InnerText = address;
  59. if (node.Attributes["contract"].InnerText == "LogicCommon")
  60. {
  61. LogicCommonCfgName = node.Attributes["name"].InnerText;
  62. LogicCommonAddress = node.Attributes["address"].InnerText;
  63. }
  64. }
  65. xmlDoc.Save("Rca.exe.config");
  66. }

以上就是我們?yōu)榇蠹医榻B的WCF修改App.config配置文件的全部操作步驟。


文章標(biāo)題:WCF修改App.config配置文件技巧分享
當(dāng)前URL:http://www.5511xx.com/article/dpjocog.html