Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1022 was 919, checked in by kgrading, 16 years ago

refactored for #418, disabled the Client Console Project

File size: 1.7 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;
9
10namespace HeuristicLab.Hive.Client.Core.ClientConsoleService {
11  public class ClientConsoleServer {
12
13    DiscoveryService discService = new DiscoveryService();
14   
15    private bool AddMexEndpoint(ServiceHost serviceHost) {
16      if (serviceHost != null) {
17        ServiceMetadataBehavior behavior =
18            new ServiceMetadataBehavior();
19        serviceHost.Description.Behaviors.Add(behavior);
20
21        return serviceHost.AddServiceEndpoint(
22          typeof(IMetadataExchange),
23          MetadataExchangeBindings.CreateMexTcpBinding(),
24          "mex") != null;
25      } else
26        return false;
27    }
28   
29    public ServiceHost StartClientConsoleServer(Uri uriTcp) {
30      IClientConsoleCommunicator[] clientConsoleServerInstances =
31        discService.GetInstances<IClientConsoleCommunicator>();
32
33      if (clientConsoleServerInstances.Length > 0) {
34        ServiceHost serviceHost =
35                new ServiceHost(clientConsoleServerInstances[0].GetType(),
36                  uriTcp);
37
38        System.ServiceModel.Channels.Binding binding =
39          new NetTcpBinding();
40
41        serviceHost.AddServiceEndpoint(
42          typeof(IClientConsoleCommunicator),
43              binding,
44              "ClientConsoleCommunicator");
45
46        AddMexEndpoint(serviceHost);
47
48        serviceHost.Open();
49        return serviceHost;
50      } else {
51        return null;
52      }
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.