Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/ServiceLocator.cs @ 4316

Last change on this file since 4316 was 4316, checked in by cneumuel, 14 years ago

made streaming wcf-services work with Transport-Security and net.tcp but with Message-Level Credentials (#1168)

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6using System.ServiceModel;
7using HeuristicLab.Hive.Contracts.Interfaces;
8using HeuristicLab.Hive.Contracts;
9using System.ServiceModel.Description;
10
11namespace HeuristicLab.Hive.Server.ServerConsole {
12
13  internal class ServiceLocator {
14    private static IServerConsoleFacade serverConsoleFacade = null;
15
16    internal static string Address { get; set; }
17    internal static string Port { get; set; }
18    internal static string Username { get; set; }
19    internal static string Password { get; set; } // [chn] TODO: Don't store plaintext password in memory!
20
21    internal static ISlaveManager GetSlaveManager() {
22      return GetServerConsoleFacade() as ISlaveManager;
23    }
24
25    internal static IJobManager GetJobManager() {
26      return GetServerConsoleFacade() as IJobManager;
27    }
28
29    internal static IServerConsoleFacade GetServerConsoleFacade() {
30      if (serverConsoleFacade == null && Address != String.Empty && Port != String.Empty) {
31        ChannelFactory<IServerConsoleFacade> factory = new ChannelFactory<IServerConsoleFacade>("ServerConsoleHttpEndpoint");
32        WcfSettings.SetEndpointAddress(factory.Endpoint, Address);
33
34        factory.Credentials.UserName.UserName = Username;
35        factory.Credentials.UserName.Password = Password;
36
37        IServerConsoleFacade client = factory.CreateChannel();
38
39        ((ICommunicationObject)client).Faulted += ServiceLocator_Faulted;
40        serverConsoleFacade = client;
41      }
42      return serverConsoleFacade;
43    }
44
45    static void ServiceLocator_Faulted(object sender, EventArgs e) {
46      ((ICommunicationObject)serverConsoleFacade).Abort();
47      ((ICommunicationObject)serverConsoleFacade).Faulted -= ServiceLocator_Faulted;
48      serverConsoleFacade = null;
49    }
50
51    internal static void ShutDownFacade() {
52      serverConsoleFacade = null;
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.