Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Contracts/WcfSettings.cs @ 1502

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

#528 WcfSettings provides common settings for WCF Services

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ServiceModel.Channels;
6using System.ServiceModel;
7using System.Security.Cryptography.X509Certificates;
8using System.Net;
9
10namespace HeuristicLab.Hive.Contracts {
11  public static class WcfSettings {
12
13    public static Binding GetBinding() {
14      NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message);
15      return binding;
16    }
17
18    public static string GetActiveIP() {
19      return System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()[0].LocalEndPoint.Address.ToString();
20    }
21
22    public static int GetDefaultPort() {
23      return 9000;
24    }
25  }
26
27  // WARNUNG: Dieser Code wird nur für Testzertifikate benötigt, wie sie beispielsweise von makecert erstellt werden.
28  // Sie sollten diesen Code nicht in einer Produktionsumgebung verwenden.
29  public class PermissiveCertificatePolicy {
30    string subjectName;
31    static PermissiveCertificatePolicy currentPolicy;
32    PermissiveCertificatePolicy(string subjectName) {
33      this.subjectName = subjectName;
34      ServicePointManager.ServerCertificateValidationCallback +=
35          new System.Net.Security.RemoteCertificateValidationCallback(RemoteCertValidate);
36    }
37
38    public static void Enact(string subjectName) {
39      currentPolicy = new PermissiveCertificatePolicy(subjectName);
40    }
41
42    bool RemoteCertValidate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) {
43      if (cert.Subject == subjectName) {
44        return true;
45      }
46
47      return false;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.