我正在尝试使用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相同.
我正在使用ASP.NET 4.5 Web应用程序,它使用ASP.NET身份模型进行身份验证和授权.
此Web应用程序还承载WCF服务,同时使用它.还有另一个基于WPF的应用程序将使用托管的托管WCF服务(以及作为客户端本身的Web应用程序).
我想授权和验证每个WCF服务请求(来自Web应用程序客户端或WPF客户端).
在理想情况下,我想使用相同的ASP.NET身份模型来验证/授权WCF操作契约.如何从Web应用程序和WPF应用程序实现此目的?