Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ClientConsoleService/ClientConsoleServer.cs @ 1579

Last change on this file since 1579 was 1579, checked in by mbecirov, 15 years ago

#528: WCF Service secured - you need to install the certificate in order to run the application properly!

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ServiceModel.Description;
6using System.ServiceModel;
7using HeuristicLab.PluginInfrastructure;
8using HeuristicLab.Hive.Client.Core.ClientConsoleService.Interfaces;
9using HeuristicLab.Hive.Contracts;
10
11namespace HeuristicLab.Hive.Client.Core.ClientConsoleService {
12  public class ClientConsoleServer {
13
14    DiscoveryService discService = new DiscoveryService();
15   
16    private bool AddMexEndpoint(ServiceHost serviceHost) {
17      if (serviceHost != null) {
18        ServiceMetadataBehavior behavior =
19            new ServiceMetadataBehavior();
20        serviceHost.Description.Behaviors.Add(behavior);
21
22        return serviceHost.AddServiceEndpoint(
23          typeof(IMetadataExchange),
24          MetadataExchangeBindings.CreateMexTcpBinding(),
25          "mex") != null;
26      } else
27        return false;
28    }
29   
30    public ServiceHost StartClientConsoleServer(Uri uriTcp) {
31      IClientConsoleCommunicator[] clientConsoleServerInstances =
32        discService.GetInstances<IClientConsoleCommunicator>();
33
34      if (clientConsoleServerInstances.Length > 0) {
35        ServiceHost serviceHost =
36                new ServiceHost(clientConsoleServerInstances[0].GetType(),
37                  uriTcp);
38
39        serviceHost.AddServiceEndpoint(
40          typeof(IClientConsoleCommunicator),
41              WcfSettings.GetBinding(),
42              "ClientConsoleCommunicator");
43
44        AddMexEndpoint(serviceHost);
45
46        serviceHost.Open();
47        return serviceHost;
48      } else {
49        return null;
50      }
51    }
52  }
53}
Note: See TracBrowser for help on using the repository browser.