1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.ServiceModel.Description;
|
---|
6 | using System.ServiceModel;
|
---|
7 | using HeuristicLab.PluginInfrastructure;
|
---|
8 | using HeuristicLab.Hive.Client.Core.ClientConsoleService.Interfaces;
|
---|
9 | using HeuristicLab.Hive.Contracts;
|
---|
10 |
|
---|
11 | namespace 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 | }
|
---|