How to convert ServiceEndpointElement to ServiceEndpoint

I am trying to load a set of WCF services into a Service Host using MEF. I implemented my own service host, which should create a ServiceDescription.

To create this, I need a list of endpoints provided by each service. In my case, each utility DLL provides a DLL configuration file that has a service model section for services in the DLL.

I can read the section of each service using the imported MEF type as follows:

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

Now, I would like to create a list so that my host can start using open endpoints.

So, I do the following:

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

, " " . endpointElement ? - .NET? , , .NET ServiceHost .

+5

All Articles