Par*_*agS 5 configuration wcf mef
我正在尝试使用MEF在服务主机中加载一组WCF服务.我实现了一个需要创建ServiceDescription的自定义服务主机.
为了创建它,我需要每个服务公开的端点列表.在我的例子中,每个服务DLL公开一个DLL Config文件,该文件具有DLL中服务的服务模型部分.
我可以使用MEF导入类型读取每个服务的部分,如下所示:
var filemap = new System.Configuration.ExeConfigurationFileMap ();
filemap.ExeConfigFilename = serviceType.Assembly.Location + ".config";
System.Configuration.Configuration config =
System.Configuration.ConfigurationManager.OpenMappedExeConfiguration
(filemap,
System.Configuration.ConfigurationUserLevel.None);
var serviceModel = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup (config);
Run Code Online (Sandbox Code Playgroud)
现在,我想生成一个List,以便我的主机可以开始使用公开的端点.
所以,我做了以下事情:
System.Generic.List<ServiceEndpoint> endpointsList = new List<ServiceEndpoint> ();
var serviceModel = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup (config);
foreach (System.ServiceModel.Configuration.ServiceElement se in serviceModel.Services.Services) {
foreach (ServiceEndpointElement endpointElement in se.Endpoints) {
ServiceEndpoint endpoint;
// I need help here.
endpointsList.Add (endpoint);
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅上面的代码中的"我需要帮助".我应该如何从上面的endpointElement填充上面的端点对象的属性?是否有一些转换器可用于.NET?我想这必须与.NET内部用于从配置文件加载ServiceHost相同.
| 归档时间: |
|
| 查看次数: |
519 次 |
| 最近记录: |