public void Init()
        {
            try
            {
                ConnectorFramework serverConnectorFramework = new ConnectorFramework();
                ConnectorServerService.ConnectorServerService.InitializeConnectors(serverConnectorFramework.LocalManager);

                foreach (var connectorInfo in serverConnectorFramework.LocalManager.ConnectorInfos)
                {
                    Trace.TraceInformation("Found Connector {0}", connectorInfo.ConnectorKey);
                }

                int freePort = FreePort;
                EndpointAddress serviceAddress =
                    new EndpointAddress(String.Format("http://localhost:{0}/openicf", freePort));

                var secureString = new GuardedString();
                "changeit".ToCharArray().ToList().ForEach(p => secureString.AppendChar(p));

                ClientAuthenticationValidator validator = new ClientAuthenticationValidator();
                validator.Add(new SingleTenantPrincipal(serverConnectorFramework), secureString.GetBase64SHA1Hash());

                _close = Start(validator, serviceAddress);
                _close += () => serverConnectorFramework.Dispose();

                // ----------

                _clientConnectorFramework = new ConnectorFramework();

                _connectionInfo = new RemoteWSFrameworkConnectionInfo
                {
                    RemoteUri = new Uri(String.Format("http://localhost.fiddler:{0}/openicf", freePort)),
                    Principal = ConnectionPrincipal.DefaultName,
                    Password = secureString
                };
            }
            catch (Exception e)
            {
                TraceUtil.TraceException("Failed", e);
                throw;
            }
        }
        public ConnectorServiceHostFactory()
        {
            NameValueCollection settings = ConfigurationManager.AppSettings;
            String authenticatorType = settings.Get(typeof(ClientAuthenticationValidator).FullName);
            if (String.IsNullOrEmpty(authenticatorType))
            {
                throw new Exception("Missing required app configuration: " +
                                    typeof(ClientAuthenticationValidator).FullName);
            }

            var type = AppDomain.CurrentDomain.GetAssemblies()
                .Where(a => !a.IsDynamic)
                .SelectMany(a => a.GetTypes())
                .FirstOrDefault(t => t.FullName.Equals(authenticatorType));
            if (type != null)
            {
                _authenticator = (ClientAuthenticationValidator)Activator.CreateInstance(type);
                //Add Principal and SharedKey
                String keyHash = settings.Get(PropKey);
                if (null != keyHash)
                {
                    _authenticator.Add(new SingleTenantPrincipal(new ConnectorFramework()), keyHash);
                }
            }
            else
            {
                Trace.TraceWarning("Type not found: " + authenticatorType);
            }

            if (null == _authenticator)
            {
                throw new ArgumentNullException(authenticatorType);
            }
        }
        protected override void OnStart(string[] args)
        {
            try
            {
                ConnectorFramework connectorFramework = new ConnectorFramework();
                InitializeConnectors(connectorFramework.LocalManager);

                NameValueCollection settings = ConfigurationManager.AppSettings;

                String keyHash = settings.Get(PropKey);
                if (keyHash == null)
                {
                    throw new Org.IdentityConnectors.Framework.Common.Exceptions.ConfigurationException(
                        "Missing required configuration property: " + PropKey);
                }

                ClientAuthenticationValidator validator = new ClientAuthenticationValidator();
                validator.Add(new SingleTenantPrincipal(connectorFramework), keyHash);

                String facadeLifeTimeStr = settings.Get(PropFacadeLifetime);
                if (facadeLifeTimeStr != null)
                {
                    // _server.MaxFacadeLifeTime = Int32.Parse(facedeLifeTimeStr);
                }

                String disableWcf = settings.Get("disableWcf");
                OperatingSystem os = Environment.OSVersion;
                if (disableWcf == null && (os.Platform == PlatformID.Win32NT) &&
                    ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 2))))
                {
                    ServiceHost host = new ConnectorServiceHost(validator);
                    host.Open();

                    _closeAction = () => host.Close();
                    Trace.TraceInformation("Started WCF connector server");
                }
                else
                {
                    Uri[] endpointUri = ExtractEndPoint();
                    if (endpointUri == null)
                    {
                        throw new Org.IdentityConnectors.Framework.Common.Exceptions.ConfigurationException(
                            "Missing required baseAddress");
                    }
                    VtortConnectorServiceHost host = new VtortConnectorServiceHost(validator, endpointUri);
                    host.Open();

                    _closeAction = () => host.Close();
                    Trace.TraceInformation("Started WebSocketListener connector server");
                }
            }
            catch (Exception e)
            {
                TraceUtil.TraceException("Exception occured starting connector server", e);
                throw;
            }
        }