Example #1
0
        /// <summary>
        /// Starts the azure relay engine.
        /// </summary>
        public static void StartTunnelRelayEngine()
        {
            try
            {
                TunnelRelayEngine.InitializePlugins();
                ServiceHost = new WebServiceHost(typeof(WCFContract));
                ServiceHost.AddServiceEndpoint(
                    typeof(WCFContract),
                    new WebHttpRelayBinding(
                        EndToEndWebHttpSecurityMode.Transport,
                        RelayClientAuthenticationType.None),
                    ApplicationData.Instance.ProxyBaseUrl)
                .EndpointBehaviors.Add(
                    new TransportClientEndpointBehavior(
                        TokenProvider.CreateSharedAccessSignatureTokenProvider(
                            ApplicationData.Instance.ServiceBusKeyName,
                            ApplicationData.Instance.ServiceBusSharedKey)));

                ServiceHost.Open();

                // Ignore all HTTPs cert errors. We wanna do this after the call to Azure is made so that if Azure call presents wrong cert we bail out.
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, cert, chain, errs) => true);
            }
            catch (Exception ex)
            {
                Logger.LogError(CallInfo.Site(), ex, "Failed to start Service host");
                throw;
            }
        }