示例#1
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void SecureProxy <T>(this ClientBase <T> proxy, string userName, string password) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { proxy.Endpoint };

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            proxy.ClientCredentials.UserName.UserName = userName;
            proxy.ClientCredentials.UserName.Password = password;
            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }
示例#2
0
        public void SetCredentials(string userName, string password)
        {
            if (State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(Endpoint);

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            Credentials.UserName.UserName = userName;
            Credentials.UserName.Password = password;
        }
示例#3
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string userName, string password) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(factory.Endpoint);

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            factory.Credentials.UserName.UserName = userName;
            factory.Credentials.UserName.Password = password;

            factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }