コード例 #1
0
        private static ServerCommandServiceClient CreateWcfClient(LoginSettings loginSettings, Uri uri)
        {
            var binding  = GetBinding(loginSettings.IsBasicUser);
            var spn      = SpnFactory.GetSpn(uri);
            var endpoint = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity(spn));
            var client   = new ServerCommandServiceClient(binding, endpoint);

            if (loginSettings.IsBasicUser)
            {
                client.ClientCredentials.UserName.UserName = "******" + loginSettings.NetworkCredential.UserName;
                client.ClientCredentials.UserName.Password = loginSettings.NetworkCredential.Password;

                // If it's basic user, you need to specify the certificate validation mode yourself
                client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
                {
                    CertificateValidationMode = X509CertificateValidationMode.None
                };
            }
            else
            {
                client.ClientCredentials.Windows.ClientCredential = LoginSettingsCache.GetNetworkCredential(EnvironmentManager.Instance.MasterSite.ServerId);
            }

            return(client);
        }
コード例 #2
0
        internal void InitializeClientProxy()
        {
            try
            {
                LastError = string.Empty;
                string uriString;
                string address = ServerPort == 0 ? ServerAddress : ServerAddress + ":" + ServerPort;

                if (BasicUser)
                {
                    if (ServerPort == 80)
                    {
                        address = ServerAddress;
                    }
                    uriString = $"https://{address}/ManagementServer/ConfigurationApiService.svc";
                }
                else
                {
                    uriString = $"http://{address}/ManagementServer/ConfigurationApiService.svc";
                }

                Uri uri             = new UriBuilder(uriString).Uri;
                var binding         = GetBinding(BasicUser);
                var spn             = SpnFactory.GetSpn(uri);
                var endpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity(spn));
                var channel         = new ChannelFactory <IConfigurationService>(binding, endpointAddress);

                if (BasicUser)
                {
                    // Note the domain == [BASIC]
                    if (channel.Credentials != null)
                    {
                        DomainUser = "******" + Username;
                        channel.Credentials.UserName.UserName = DomainUser;
                        channel.Credentials.UserName.Password = Password;
                    }
                }
                else
                {
                    if (channel.Credentials != null)
                    {
                        channel.Credentials.Windows.ClientCredential.UserName = Username;
                        channel.Credentials.Windows.ClientCredential.Password = Password;
                        channel.Credentials.Windows.ClientCredential.Domain   = Domain;

                        // VmoClient needs the domain along with the user name
                        DomainUser = string.IsNullOrWhiteSpace(Domain) ? Username : Domain + "\\" + Username;
                    }
                }
                _client = channel.CreateChannel();

                ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

                Connected = false;
            }
            catch (EndpointNotFoundException)
            {
            }
        }
コード例 #3
0
        public IConfigurationService CreateClientProxy(string address, LoginSettings loginSettings)
        {
            bool basic = loginSettings != null && loginSettings.IsBasicUser;

            string hostName = address;
            string uriString;

            if (ServerType == ServerTypeEnum.Corporate)
            {
                uriString = new UriBuilder(loginSettings.UriCorporate).Uri.ToString() + "ManagementServer/ConfigurationApiService.svc";

                /*
                 * if (basic)
                 * {
                 *  if (Serverport == 80)
                 *      hostName = ServerAddress;
                 *  uriString = String.Format("https://{0}/ManagementServer/ConfigurationApiService.svc", hostName);
                 * }
                 * else
                 *  uriString = String.Format("http://{0}/ManagementServer/ConfigurationApiService.svc", hostName);
                 */
            }
            else
            {
                uriString = String.Format("http://{0}/Config", hostName);
            }
            ChannelFactory <IConfigurationService> channel = null;

            Uri uri             = new UriBuilder(uriString).Uri;
            var binding         = GetBinding(basic, ServerType == ServerTypeEnum.Corporate);
            var spn             = SpnFactory.GetSpn(uri);
            var endpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity(spn));

            channel = new ChannelFactory <IConfigurationService>(binding, endpointAddress);

            ClientTokenHelper clientTokenHelper = new ClientTokenHelper(ServerAddress);

            channel.Endpoint.Behaviors.Add(new TokenServiceBehavior(clientTokenHelper));

            if (loginSettings != null)
            {
                if (basic)
                {
                    channel.Credentials.UserName.UserName = "******" + loginSettings.NetworkCredential.UserName;
                    channel.Credentials.UserName.Password = loginSettings.NetworkCredential.Password;
                    channel.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
                    {
                        CertificateValidationMode = X509CertificateValidationMode.None,
                    };
                }
                else
                {
                    channel.Credentials.Windows.ClientCredential.UserName = loginSettings.NetworkCredential.UserName;
                    channel.Credentials.Windows.ClientCredential.Password = loginSettings.NetworkCredential.Password;
                }
            }
            return(channel.CreateChannel());
        }
コード例 #4
0
        private IConfigurationService GetConfigurationServiceContext(Uri uri)
        {
            var newUri            = new Uri($"http://{uri.Host}:{uri.Port}/ManagementServer/ConfigurationApiService.svc");
            var binding           = GetBinding(false, true);
            var spn               = SpnFactory.GetSpn(newUri);
            var endpoint          = new EndpointAddress(newUri, EndpointIdentity.CreateSpnIdentity(spn));
            var channelFactory    = new ChannelFactory <IConfigurationService>(binding, endpoint);
            var clientTokenHelper = new ClientTokenHelper(newUri.Host);

            channelFactory.Endpoint.Behaviors.Add(new TokenServiceBehavior(clientTokenHelper));
            channelFactory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            return(channelFactory.CreateChannel());
        }
コード例 #5
0
        internal void InitializeClientProxy()
        {
            try
            {
                string uriString;
                string address = Serverport == 0 ? ServerAddress : ServerAddress + ":" + Serverport;

                if (BasicUser)
                {
                    if (Serverport == 80)
                    {
                        address = ServerAddress;
                    }
                    uriString = String.Format("https://{0}/ManagementServer/ConfigurationApiService.svc", address);
                }
                else
                {
                    uriString = String.Format("http://{0}/ManagementServer/ConfigurationApiService.svc", address);
                }

                ChannelFactory <IConfigurationService> channel = null;

                Uri uri             = new UriBuilder(uriString).Uri;
                var binding         = GetBinding(BasicUser);
                var spn             = SpnFactory.GetSpn(uri);
                var endpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity(spn));
                channel = new ChannelFactory <IConfigurationService>(binding, endpointAddress);

                if (BasicUser)
                {
                    // Note the domain == [BASIC]
                    channel.Credentials.UserName.UserName = "******" + Username;
                    channel.Credentials.UserName.Password = Password;
                    channel.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
                    {
                        CertificateValidationMode = X509CertificateValidationMode.None,
                    };
                }
                else
                {
                    channel.Credentials.Windows.ClientCredential.UserName = Username;
                    channel.Credentials.Windows.ClientCredential.Password = Password;
                }
                _client = channel.CreateChannel();

                Connected = false;
            }
            catch (EndpointNotFoundException)
            {
            }
        }
コード例 #6
0
        public static IConfigurationService CreateClient(NetworkCredential credential, string hostname, int port)
        {
            // Basic users require HTTPS communication
            var isBasicUser = credential.Domain == "[BASIC]";
            var uriBuilder  = GetUriBuilder(isBasicUser, hostname, port);

            System.ServiceModel.Channels.Binding binding = GetBinding(isBasicUser);
            binding.Namespace = "VideoOS.ConfigurationAPI";

            var endpointAddress = new EndpointAddress(uriBuilder.Uri, EndpointIdentity.CreateSpnIdentity(SpnFactory.GetSpn(uriBuilder.Uri)));

            ChannelFactory <IConfigurationService> channel = GetChannelFactoryWithCredentials(binding, endpointAddress, isBasicUser, credential);

            channel.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
            {
                CertificateValidationMode = X509CertificateValidationMode.None,
            };

            IConfigurationService client = channel.CreateChannel();

            return(client);
        }
コード例 #7
0
        /// <summary>
        /// Constructor for the BasicConnection, which performs and sets some start-up routines
        /// </summary>
        /// <param name="isCServer">If the server is a C server</param>
        /// <param name="username">Username to use</param>
        /// <param name="password">Password to use</param>
        /// <param name="hostname">The hostname</param>
        /// <param name="port">Which port to use</param>
        public BasicConnection(bool isCServer, String username, String password, String hostname, int port)
        {
            //Precondition
            if (hostname.StartsWith("http://"))
            {
                hostname = hostname.Substring("http://".Length);
            }

            IsCServer  = isCServer;
            _serverUrl = hostname;
            _username  = username;
            _password  = password;
            _port      = port;

            if (IsCServer)
            {
                // SSL
                _uri = new Uri($"https://{_serverUrl}:{_port}/ManagementServer/ServerCommandService.svc");

                // Create Soap class from interface
                CServer = new ServerCommandServiceClient(GetBinding(),
                                                         new EndpointAddress(_uri, EndpointIdentity.CreateSpnIdentity(SpnFactory.GetSpn(_uri))));

                // Set basic credentials
                CServer.ClientCredentials.UserName.UserName = username;
                CServer.ClientCredentials.UserName.Password = password;
                // TODO Any certificate is accepted as OK !!
                CServer.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
                {
                    CertificateValidationMode = X509CertificateValidationMode.None,
                };

                // Open service (internally)
                CServer.Open();

                // Give OS a few milliseconds to get ready
                long tickStop = DateTime.Now.Ticks + 1000000; // 1.000.000 ticks == 100 ms
                while (DateTime.Now.Ticks < tickStop && CServer.State == CommunicationState.Opening)
                {
                    Thread.Sleep(5);
                }
            }
            else
            {
                _eServer = new ServerCommandService($"http://{_serverUrl}:{_port}/ServerCommandService/servercommandservice.asmx");

                String uri = $"http://{_serverUrl}";
                _uri = new Uri(uri);


                CredentialCache   credCache   = new CredentialCache();
                NetworkCredential credentials = new NetworkCredential(_username, _password);
                credCache.Add(new Uri(uri), "Basic", credentials);
                _eServer.Credentials = credCache;
            }
        }
コード例 #8
0
        /// <summary>
        /// Constructor for the BasicConnection, which performs and sets some start-up routines
        /// </summary>
        /// <param name="username">Username to use</param>
        /// <param name="password">Password to use</param>
        /// <param name="hostname">The hostname</param>
        /// <param name="port">Which port to use</param>
        public BasicConnection(String username, String password, String hostname, int port)
        {
            //Precondition
            if (hostname.StartsWith("http://"))
            {
                hostname = hostname.Substring("http://".Length);
            }

            _serverUrl = hostname;
            _username  = username;
            _password  = password;
            _port      = port;

            // SSL
            _uri = new Uri($"https://{_serverUrl}:{_port}/ManagementServer/ServerCommandService.svc");

            // Create Soap class from interface
            Server = new ServerCommandServiceClient(GetBinding(),
                                                    new EndpointAddress(_uri, EndpointIdentity.CreateSpnIdentity(SpnFactory.GetSpn(_uri))));

            // Set basic credentials
            Server.ClientCredentials.UserName.UserName = username;
            Server.ClientCredentials.UserName.Password = password;
            // TODO Any certificate is accepted as OK !!
            Server.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
            {
                CertificateValidationMode = X509CertificateValidationMode.None,
            };

            // Open service (internally)
            Server.Open();

            // Give OS a few milliseconds to get ready
            long tickStop = DateTime.Now.Ticks + 1000000; // 1.000.000 ticks == 100 ms

            while (DateTime.Now.Ticks < tickStop && Server.State == CommunicationState.Opening)
            {
                Thread.Sleep(5);
            }
        }