Пример #1
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string clientCertificateName) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            factory.Credentials.ClientCertificate.SetCertificate(storeLocation, storeName, findType, clientCertificateName);

            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(factory.Endpoint);

            SecurityBehavior.ConfigureBusinessToBusiness(endpoints);

            factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }
Пример #2
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;
        }
Пример #3
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string domain, string userName, string password, TokenImpersonationLevel impersonationLevel) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { factory.Endpoint };

            SecurityBehavior.ConfigureIntranet(endpoints);

            NetworkCredential credentials = new NetworkCredential();

            credentials.Domain   = domain;
            credentials.UserName = userName;
            credentials.Password = password;

            factory.Credentials.Windows.ClientCredential          = credentials;
            factory.Credentials.Windows.AllowedImpersonationLevel = impersonationLevel;
        }
Пример #4
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");
            }
            }
        }
Пример #5
0
 public static T CreateChannel(InstanceContext <C> context, Binding binding, EndpointAddress endpointAddress)
 {
     return(DuplexChannelFactory <T> .CreateChannel(context.Context, binding, endpointAddress));
 }
Пример #6
0
 public static T CreateChannel(C callback, Binding binding, EndpointAddress endpointAddress)
 {
     return(DuplexChannelFactory <T> .CreateChannel(callback, binding, endpointAddress));
 }
Пример #7
0
 public static T CreateChannel(InstanceContext <C> context, string endpointName)
 {
     return(DuplexChannelFactory <T> .CreateChannel(context.Context, endpointName));
 }
Пример #8
0
 public static T CreateChannel(C callback, string endpointName)
 {
     return(DuplexChannelFactory <T> .CreateChannel(callback, endpointName));
 }
Пример #9
0
 public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string domain, string userName, string password) where T : class
 {
     SetCredentials(factory, domain, userName, password, TokenImpersonationLevel.Identification);
 }
Пример #10
0
 public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string clientCertificateName) where T : class
 {
     SetCredentials(factory, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, clientCertificateName);
 }