Example #1
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void AnonymousProxy <T>(this ClientBase <T> proxy) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { proxy.Endpoint };
            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

            SecurityBehavior.ConfigureAnonymous(endpoints);
        }
Example #2
0
        public static void SetSecurityMode <T, C>(this DuplexChannelFactory <T, C> factory, ServiceSecurity mode) where T : class
        {
            switch (mode)
            {
            case ServiceSecurity.None:
            {
                if (factory.State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(factory.Endpoint);

                SecurityBehavior.ConfigureNone(endpoints);

                break;
            }

            case ServiceSecurity.Anonymous:
            {
                if (factory.State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(factory.Endpoint);

                SecurityBehavior.ConfigureAnonymous(endpoints);

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

                break;
            }

            default:
            {
                throw new InvalidOperationException(mode + " is unsupported with this constructor");
            }
            }
        }
Example #3
0
        public void SetSecurityMode(ServiceSecurity mode)
        {
            switch (mode)
            {
            case ServiceSecurity.None:
            {
                if (State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(Endpoint);

                SecurityBehavior.ConfigureNone(endpoints);

                break;
            }

            case ServiceSecurity.Anonymous:
            {
                if (State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(Endpoint);

                SecurityBehavior.ConfigureAnonymous(endpoints);
                break;
            }

            default:
            {
                throw new InvalidOperationException(mode + " is unsupported with this constructor");
            }
            }
        }