自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WCF修改App.config配置文件技巧分享

開發(fā) 開發(fā)工具
WCF修改App.config配置文件的正確操作方法只要按照我們給出的這樣一段代碼來進(jìn)行操作就能夠順利完成。大家可以以此為參考學(xué)習(xí)對象。

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

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");  

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

【編輯推薦】

  1. WCF openation實(shí)際應(yīng)用異常解決方案
  2. MSMQ使用WCF正確實(shí)現(xiàn)技巧講解
  3. WCF PreSession模式保持調(diào)用狀態(tài)
  4. WCF PreCal模式基本代碼示例解析
  5. WCF使用Nhibernate具體操作步驟圖解
責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-08-24 17:20:34

C#項(xiàng)目實(shí)例

2010-02-23 14:17:20

WCF配置文件

2009-12-21 11:19:50

WCF配置文件

2010-02-22 10:18:18

WCF配置文件

2025-02-10 00:55:00

2009-11-05 10:30:41

WCF Address

2009-12-21 13:06:05

WCF Address

2010-02-22 17:58:06

WCF異步上傳

2010-03-01 13:06:49

WCF繼承

2021-08-13 13:55:03

鴻蒙HarmonyOS應(yīng)用

2009-11-09 13:31:09

WCF服務(wù)端配置

2010-02-26 14:12:27

WCF元數(shù)據(jù)

2010-02-22 15:20:54

WCF WS-Disc

2010-02-23 16:46:47

WCF并發(fā)能力

2010-02-22 17:21:02

WCF消息交換

2010-02-25 15:25:19

WCF通道

2009-12-22 19:00:08

WCF回調(diào)

2010-02-24 11:22:04

WCF方法重載

2009-10-26 19:22:29

VB.NET使用Log

2010-03-01 17:39:07

WCF Address
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號