Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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");
            }
            }
        }
Exemplo n.º 5
0
 public static T CreateChannel(InstanceContext <C> context, Binding binding, EndpointAddress endpointAddress)
 {
     return(DuplexChannelFactory <T> .CreateChannel(context.Context, binding, endpointAddress));
 }
Exemplo n.º 6
0
 public static T CreateChannel(C callback, Binding binding, EndpointAddress endpointAddress)
 {
     return(DuplexChannelFactory <T> .CreateChannel(callback, binding, endpointAddress));
 }
Exemplo n.º 7
0
 public static T CreateChannel(InstanceContext <C> context, string endpointName)
 {
     return(DuplexChannelFactory <T> .CreateChannel(context.Context, endpointName));
 }
Exemplo n.º 8
0
 public static T CreateChannel(C callback, string endpointName)
 {
     return(DuplexChannelFactory <T> .CreateChannel(callback, endpointName));
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }