[901] | 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.Communication.Interfaces;
|
---|
| 9 |
|
---|
| 10 | namespace HeuristicLab.Hive.Client.Communication {
|
---|
| 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 | }
|
---|