![](/img/trans.png)
[英]The configuration section 'system.ServiceModel' cannot be read, missing section declaration
[英]How do I read the “System.ServiceModel” configuration section group from a class library?
有什么方法可以訪問基於類的(dll)項目中的“ System.ServiceModel”客戶端配置,即app.config?
ConfigurationManager.GetSection(string)
允許您從正在執行的應用程序的app.config或web.config中打開一個部分。 但是system.ServiceModel
不是一個節,而是一個節組。 ConfigurationManager
沒有提供獲取節組的方法。
有多種方法可以在沒有Configuration
情況下進行ConfigurationManager
,但這有點混亂,因為您必須區分app.config和web.config。
但是,如果您可以跳過system.ServiceModel
到所需的實際配置組,那么這真的很容易,因為您可以使用ConfigurationManager
。 例如,
var section = ConfigurationManager.GetSection("system.serviceModel/client");
或者,您可以將其設為強類型:
var section = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
要么
var behaviorSection =
(BehaviorsSection)ConfigurationManager.GetSection("system.serviceModel/behaviors");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.